A regex doubt
Posted: Sun May 03, 2009 4:20 pm
Why does the regex "a+|aabb" match the test string "aabb" as "aa" and not "aabb".
My understanding is
The regex "a+|aabb" means
1. "one or more a's"
or
2. the exact string "aabb"
So for the test string "aabb", condition #2 i.e. "aabb" is satisfied. Also it is the longest match.
Also if you change the regex to "aabb|a+" for the same test string "aabb" it matches "aabb" .
Could some one clear my doubt
Many thanks in advance.
My understanding is
The regex "a+|aabb" means
1. "one or more a's"
or
2. the exact string "aabb"
So for the test string "aabb", condition #2 i.e. "aabb" is satisfied. Also it is the longest match.
Also if you change the regex to "aabb|a+" for the same test string "aabb" it matches "aabb" .
Could some one clear my doubt
Many thanks in advance.