Reputation: 7128
This regular expression seems to break in Chrome, Firefox and IE11...
'abc(def'.match('\((\w*)')
Is there anything wrong with it? Is there a better way to escape the ( character?
If I do it this way, they are happy:
/\((\w*)/.exec('abc(def')
Upvotes: 1
Views: 134
Reputation: 89557
It's because your regex must be enclosed between /
instead of '
:
'abc(def'.match(/\((\w*)/)
Upvotes: 2
Reputation: 149010
You'll need to escape the \
characters if you construct the regular expression from a string literal:
'abc(def'.match('\\((\\w*)')
Or simply use a regular expression literal:
'abc(def'.match(/\((\w*)/)
Upvotes: 4