Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript regexp for word boundary detection with parenthesis

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?

like image 881
suzee Avatar asked Sep 27 '22 00:09

suzee


1 Answers

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

like image 112
d0nut Avatar answered Oct 03 '22 02:10

d0nut