Regex to match a word with + (plus) signs

后端 未结 5 1476
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 01:46

I\'ve spent some time, but still have to solution. I need regular expression that is able to match a words with signs in it (like c++) in string.

I\'ve used /\

5条回答
  •  死守一世寂寞
    2020-12-04 02:13

    The problem isn't with the plus character, that you've escaped correctly, but the \b sequence. It indicates a word boundary, which is a point between a word character (alphanumeric) and something else. Plus isn't a word character, so for \b to match, there would need to be a word character directly after the last plus sign.

    \bC\+\+\b matches "Test C++Test" but not "Test C++ Test" for example. Try something like \bC\+\+\s if you expect there to be a whitespace after the last plus sign.

提交回复
热议问题