in reply to Re^3: Non-greedy substitution
in thread Non-greedy substitution

Your mental model of what «.+?» does is severely flawed

Well, yes...hence the need to ask the question...

«.+?» doesn't do any checks related to commas

But I included the comma in my example...perhaps I could have formatted it so it was more prominent.

Replies are listed 'Best First'.
Re^5: Non-greedy substitution
by ikegami (Patriarch) on Nov 18, 2024 at 01:34 UTC

    I know. But you said you thought «,.+?$» searches for "the shortest possible match within the string that starts with a comma". Since neither «,» nor «$» searches for the shortest possible anything (starting with a comma or otherwise), that means you though «.+?» did that. «.+?» doesn't search for commas, which it would need to do to find "the shortest possible match within the string that starts with a comma".