Regex Cheat Sheet
A searchable regular expression reference: character classes, anchors, quantifiers, groups, lookaround, flags and Unicode properties, each with a live example.
Try it
Nothing matches that search.
How to use the regex cheat sheet
- Search the box for what you need — “lookahead”, “\b”, “named group” — and the tables filter to matching rows.
- Press Try on any row to load its example into the tester at the top; every match is highlighted straight away.
- Edit the pattern, the flags or the sample text in that tester to check your own case before you paste it into code.
FAQ
Does this cover Python, PHP or Java regex?
The tables describe JavaScript (ECMAScript) regular expressions, and the live examples run in your browser's own engine. Most of it — classes, quantifiers, groups, lookaround, Unicode properties — is identical in Python, PCRE and Java. Where JavaScript differs the row says so, for example that \A, \z, atomic groups and possessive quantifiers do not exist here.
When do I need the u flag?
Whenever you use \p{…} Unicode properties, \u{…} code points, or work with emoji and other characters outside the Basic Multilingual Plane. Without u, a single emoji counts as two separate UTF-16 units and . can split it in half.
What is the difference between greedy and lazy?
.+ is greedy: it takes as much as it can and then gives characters back until the rest of the pattern fits. .+? is lazy: it takes as little as possible and grows only when it has to. For anything shaped like a tag or a quoted string, lazy is almost always what you want.