What does this mean please?
(\s|^)
I know what \s
is. What I don't get is why "or ^" (|^
).
Thank you.
Boils down to "whitespace, or the start of the line"
\s
is a white space. ^
is start of line.
This regular expressions means "start of line or white space"
The ^
metacharacter indicates that the match should occur at the beginning of the line. So it currently checks for whitespace or the beginning of the line. Perhaps the pattern is meant to check for a word boundary, in which case \b
might be a better choice.
the ^ outside of [] means start of the line.
such as '^hello' matches "hello" but not "hi, er hello"
精彩评论