4 ms·
Is the early example in the document correct? Using an input string of abc123 he claims [a-z]+\d+ will match the entire string (which I agree with). He then s
by larubbio 12y ago
Is the early example in the document correct?
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'?
- simcop2387 12y agono it'll still match but because both are non-greedy it could match on just c1 instead of abc123.
- prawks 12y agoIt 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.
- gatehouse 12y agohttp://regex101.com/r/aR5xM2 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.