in reply to Re^2: Non-greedy substitution
in thread Non-greedy substitution
Your mental model of what «.+?» does is severely flawed. For starters, it doesn't permit patterns to have multiple subpatterns that can match substrings of different lengths.
«.+?» does not mean "the shortest possible match within the string that starts with a comma".
«.+» means "one or more non-LF characters, trying in order of decreasing length", and
«.+?» means "one or more non-LF characters, trying in order of increasing length".
Note that lack of mention of comma. «.+?» doesn't do any checks related to commas. The comma is matched independently.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Non-greedy substitution
by Bod (Parson) on Nov 15, 2024 at 21:38 UTC | |
by ikegami (Patriarch) on Nov 18, 2024 at 01:34 UTC |