Timeline for Why is regex [0-9]{0,2} not greedy in sed?
Current License: CC BY-SA 4.0
3 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 20, 2019 at 9:03 | comment | added | ilkkachu | On a GNU system, the repetition operators stack, ? after + (using ERE syntax) makes the whole thing optional (same as *), and {2,4}? matches 0, 2, 3 or 4 repetitions (try grep -Eoe 'ba{2,4}?b' against bb, bab, baab). *? is just the same as * since * can already match zero repetitions. The thing where ? makes a pattern non-greedy is a feature of Perl regexes. | |
| Jul 20, 2019 at 5:01 | comment | added | Ed Morton | wrt I’m not sure why it just ignores the ? - because ? after another repetition RE metachar (* in this case) is undefined behavior per POSIX and since in other contexts it means zero-or-1 just ignoring it is as reasonable approach as any. Essentially .*? should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?). | |
| Jul 20, 2019 at 1:37 | history | answered | G-Man Says 'Reinstate Monica' | CC BY-SA 4.0 |