I am having a problem using the following regex. It works fine in regexr and rubular but it gives me an error when running it on node.js. I am fairly new to using regex and i'm not sure what i'm doing wrong. It will work if I knock off the (?<= )
so I presume that is the problem.
I'm trying to match 'is' with a leading and trailing space using /(?<= )is(?= )|==/g
Example with test words:
Node error output
temp = temp.replace(/(?<= )is(?= )|==/g, '===');
^
SyntaxError: Invalid regular expression: /(?<= )is(?= )|==/: Invalid group
at new RegExp (unknown source)
I am having a problem using the following regex. It works fine in regexr and rubular but it gives me an error when running it on node.js. I am fairly new to using regex and i'm not sure what i'm doing wrong. It will work if I knock off the (?<= )
so I presume that is the problem.
I'm trying to match 'is' with a leading and trailing space using /(?<= )is(?= )|==/g
Example with test words:
http://regexr.?33781
Node error output
temp = temp.replace(/(?<= )is(?= )|==/g, '===');
^
SyntaxError: Invalid regular expression: /(?<= )is(?= )|==/: Invalid group
at new RegExp (unknown source)
Share
Improve this question
edited Dec 21, 2012 at 16:34
FThompson
28.7k13 gold badges62 silver badges95 bronze badges
asked Dec 21, 2012 at 16:32
SkinnyG33kSkinnyG33k
1,7314 gold badges24 silver badges30 bronze badges
0
2 Answers
Reset to default 16JavaScript regex does not support lookbehind at all.
Sources:
- http://www.regular-expressions.info/lookaround.html#limitbehindand
- http://www.regular-expressions.info/javascript.html
- https://developer.mozilla/en-US/docs/JavaScript/Guide/Regular_Expressions
However, you can fake it in some cases.
Quite simply, this is because JavaScript regular expressions have no support for lookbehinds:
http://www.regular-expressions.info/javascript.html
Lookbehind is not supported at all. Lookahead is fully supported.