Regex to match a word with + (plus) signs
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.
+
is a special character so you need to escape it
\bC\+\+(?!\w)
Note that we can't use \b
because +
is not a word-character.
Plus sign have special meaning so you will have to escape it with \
. The same rule applies to these characters: \, *, +, ?, |, {, [, (,), ^, $,., #,
and white space
UPDATE: the problem was with \b
sequence