I have a string "I am a robot, I have been named 456/m(4). Forget the name (it does not mean anything)"
Now I would like to extract all words from this string for this I use the regular expression:
/\b[\w\S]+\b/g
it returns me all the words in the string except that there is a word "456/(4" instead of "456/(4)". I understand that it is due to the fact that it is a word boundary, but is there a way I could say that it is not a legal word boundary since there was no "legal" starting parenthesis?
I made it even better now. It does exactly what you want.
\b(?>\([\w\/]+\)|[\w\/])+
Regex101
If you want a version that's javascript friendly:
((?:(?=(\([\w\/]+\)|[\w\/]))\2)+)
Just use capture group #1 here.
Regex101
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With