Re:Why Using .* in Regular Expressions Is Almost Never What ...
by simcop2387 on Wednesday June 04, 2014 @11:32AM
(#7846133)
no it'll still match but because both are non-greedy it could match on just c1 instead of abc123.
Re:Why Using .* in Regular Expressions Is Almost Never What ...
by prawks on Wednesday June 04, 2014 @01:21PM
(#7846846)
It could match on c1, but I believe since most (all?) regex parsers parse left-to-right, it will match the a, look for another a-z character or a digit, find b, repeat, find c, then find 1 which completes the pattern.
Re:Why Using .* in Regular Expressions Is Almost Never What ...
by gatehouse on Wednesday June 04, 2014 @01:22PM
(#7846855)
http://regex101.com/r/aR5xM2
I used this tester posted elsewhere in the thread, it seems like since the lazy components expand "as needed" to achieve a match, it will succeed on "abc1".
EDIT: I wrapped it in a group for clarity.
Using an input string of abc123 he claims [a-z]+\d+ will match the entire string (which I agree with). He then says that [a-z]+?\d+? will only match abc1. Wouldn't it fail since the non-greedy match on [a-z] would just match 'a' causing the non-greedy match on \d to fail trying to match 'b'?