How does \b work when using regular expressions?

前端 未结 7 938
孤街浪徒
孤街浪徒 2020-12-03 14:03

If I have a sentence and I wish to display a word or all words after a particular word has been matched ahead of it, for example I would like to display the word fox

相关标签:
7条回答
  • 2020-12-03 14:53

    The \b token is kind of special. It doesn't actually match a character. What it does is it matches any position that lies at the boundary of a word (where "word" in this case is anything that matches \w). So the pattern (?<=brown\s)(\w+) would match "bbbbrown fox", but (?<=\bbrown\s)(\w+) wouldn't, since the position between "bb" and "brown" is in the middle of a word, not at its boundary.

    0 讨论(0)
提交回复
热议问题