How does \b work when using regular expressions?

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

    \b is a "word boundary" and is the position between the start or end of a word and then "non-word" characters.

    Its main use is to simplify the selection of a whole word to \bbrown\s will match:

    ^brown brown 99brown _brown

    Its more or less equivalent to "\W*" except when "capturing" strings as "\b" matches the start of the word rather than the non-word character preceding or following the word.

提交回复
热议问题