开发者

Regular Expression Explanation

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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜