Cheatsheet Pages / Regex Cheatsheet

Greedy vs lazy matching in regex — .* vs .*?

Your pattern matched way too much: it ran to the last possible end instead of stopping at the first.

Patterns use the syntax shared by PCRE / Python / JavaScript; engine differences are flagged in the cheatsheet where they matter. Test any pattern at regex101.com — and pick the matching engine.

<.*>
# greedy: on "<b>hi</b>" matches the whole "<b>hi</b>"
<.*?>
# lazy: on "<b>hi</b>" matches "<b>" then "</b>" separately

Good to know

Quantifiers are greedy by default; adding ? makes them lazy. Possessive quantifiers (*+, ++) exist in PCRE/Java but not in Python or JavaScript.

Regex Cheatsheet one-page card — patterns that actually work
The full one-page card — Regex Cheatsheet. Get the complete cheatsheet on GitHub