How does \b work when using regular expressions?

前端 未结 7 974
孤街浪徒
孤街浪徒 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:36

    \b is a zero width match of a word boundary.

    (Either start of end of a word, where "word" is defined as \w+)

    Note: "zero width" means if the \b is within a regex that matches, it does not add any characters to the text captured by that match. ie the regex \bfoo\b when matched will capture just "foo" - although the \b contributed to the way that foo was matched (ie as a whole word), it didn't contribute any characters.

提交回复
热议问题