I have a regex: /(?<!\<)\<[a-zA-Z0-9. _]+\>/g. Works fine in browser console if I do "(<<a1>> * <b1> * <c1> * <d1>) * <<e1>>".match(/(?<!\<)\<[a-zA-Z0-9. _]+\>/g).
Same line of code throws SyntaxError: Invalid regular expression: /(?<!<)<([a-zA-Z0-9. _]+)>/: Invalid group when executed in Node.js.
I want to match all variables in my string enclosed in < and > ignore them if enclosed by << and >>.
As an answer as well (more space):
Unless node.js uses it's own regex engine and not the JavaScript one, lookbehinds are not supported in JS, thus (?<!) cannot work. To somewhat mimic this feature from other programming languages, have a look at Flagrant Badassery or use additional packages like node-re2 or node-perl-regex.
As for the differences between Browsers, Chrome does support lookbehinds.
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