I need a regular expression in javascript that matches whole words that start or end with special characters?
It was supposed to be easy, but for some reason
after ?
doesn't behave as I expected:
> /FOO?/.exec('FOO? ')
[ 'FOO?', index: 0, input: 'FOO? ', groups: undefined ]
> /FOO?/.exec('FOO? ')
null
What I need, for instance if my word is "FOO?" (including the question mark), I want to match:
"FOO? is cool", "do you think that FOO??"
but not: "FOO is cool", "FOO?is cool", "aaFOO?is cool"
It should also work for words that start with "?". For instance, if my word if "?FOO", I want to match:
"?FOO is cool", "I love ?FOO"
but not: "FOO is cool", "FOO?is cool", "aaFOO?is cool"
I hope it makes sense.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…