I know that the regexp OR (|) operator in javascript matches if one of the sub-strings on both sides of the regexp is matched.
I also know that in JavaScript the logical (||) OR operator checks the second operand only if the first operand is false.
So I want to know if the regexp (|) (also called pipe) OR operator works the same way or it first matches both the sub-strings and then decide the match.
If I am not wrong I think it should check the second right hand sub-string only when left hand sub-string is not matched for the sake of performance.
Yes,
|in regular expressions is short circuiting.For example,
produces
while
produces
The language specification says
15.10.2.3 line 3b is where the short-circuiting is specified.