If I want to do a “whole word” search for a string with special characters, like say “A+”, how can I write a Javascript regex that will match the whole word for cases like the following:
- Is the only text in the string: “A+”
-
Is at the end of the string: “You got an A+.”
-
Is at the beginning of the string: “A+ good job!”
-
Is in the middle: “You did A+ work here.”
It should return false for:
-
Not whole word: “A++”
-
Not whole word”: “You got an A++!”
… and many other cases
I’d love to just use b:
/b(A+)b/g
…but that seems to interact poorly with special characters (in fact I’m not sure that regex can even match anything…).