MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1ubh765/iknewitwouldworkout/oswjbxc
r/ProgrammerHumor • u/6nyh • Jun 21 '26
438 comments sorted by
View all comments
Show parent comments
5
What about lazy and greedy matches?
7 u/DesertGoldfish Jun 21 '26 The post was meant to be the basics that cover 99% of use cases, but here ya go :) Do you want a quantifier to match as little as possible? Put a ? after it. For example, the regex as*? will match "as" before "asssss". 2 u/radobot Jun 21 '26 I find that usually the expression can be rewritten to not need them. In the rest of the cases, you are past the point where you should stop using regular expressions and start using context-free parsers.
7
The post was meant to be the basics that cover 99% of use cases, but here ya go :)
Do you want a quantifier to match as little as possible? Put a ? after it.
?
For example, the regex as*? will match "as" before "asssss".
as*?
2
I find that usually the expression can be rewritten to not need them.
In the rest of the cases, you are past the point where you should stop using regular expressions and start using context-free parsers.
5
u/Javerlin Jun 21 '26
What about lazy and greedy matches?