How does \b work when using regular expressions?

前端 未结 7 957
孤街浪徒
孤街浪徒 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.

提交回复
热议问题