Reputation: 2519
I am having an issue properly testing this sentence.
"code in c++ and javascript"
I want to match c++ and javascript, but not java. I solved not matching java by introducing a word boundary test on both sides \b
.
Solved with word boundary test.
Now the issue - The same approach is not working with "c++", although it seems to me it should be. Is there something I am missing?
And without word boundary
Upvotes: 4
Views: 240
Reputation: 785058
Since +
is not considered a word character, having a \b
after +
won't work.
You can fix your regex by using a negative lookahead instead of \b
on RHS:
/\bc\+\+(?!\w)/
To match both java
and c++
in alternation:
/\b(?:c\+\+|java)(?!\w)/
Upvotes: 3
Reputation: 9597
Are you trying to match both with the same regex? Or independently? This will match c++ if that's what you need:
c\+{2}
Upvotes: 2