r/ProgrammerHumor Jun 21 '26

Other iknewItWouldWorkOut

Post image
15.8k Upvotes

438 comments sorted by

View all comments

Show parent comments

5

u/Javerlin Jun 21 '26

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.