I have the following regexp:
var re = new RegExp("(^|\\s)" + classname + "(\\s|$)");
I understand \s is a white-space character; the caret means “beginning with”. What I don’t understand is the pipe character here…
How does the expression above translate into English?
Regards,
The expression
(^|\s)is an alternation. It means “either the start of the string or a whitespace character”. Similarly(\s|$)means “either the end of the string or a whitespace character”.This sort of regular expression is useful for finding a word in a space separated list where there is no space at the start or end.