Reputation: 145
I found a piece of code that accidentally outputs strange and inefficient regular expressions such as
a(a|a)b
which gets an a|a
(two identical expressions connected by |
)
Is such expression syntactically right? I can easily fix it, but I just want to know whether such expressions are valid or not, because this one seems bugs-free so far.
Upvotes: 0
Views: 67
Reputation: 6527
What the regex a(a|a)b
indicates is,
And the regex aab
indicates
And both will matches the input aab
Upvotes: 1
Reputation: 6739
Yep, this is syntactically equivalent to the regex /a(a)b/ - just slower.
Upvotes: 4