开发者

Word boundary matching in Javascript [duplicate]

This question already has answers here: What is a word boundary in regex? 开发者_运维百科 (13 answers) Closed 4 years ago.

This Regex Pattern: \bgoogle\b

Test case: http://www.google.com/

It matches.

Why?


Because a period represents a word boundary. That is, it is not part of a word, just as a space, a colon, a semicolon, or a tab character are not part of a word. \b is a zero-width assertion, meaning it does not match anything itself, it just defines something about the match.


Word boundaries with \b are very tricksy buggers indeed!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜