ADVERT
๐งต Regex Cheatsheet
Anchors, character classes, quantifiers, flags, and real-world regex patterns you can paste into your next search.
Practical regex reference with search, one-click copy, and an inline tester.
Regex Tester
Validate patterns against sample text before deployment.
Compiled as /^\w+$/g
Matches: 0
Anchors and Boundaries
Control where matches begin and end.
| Pattern | Meaning | Usage | Copy |
|---|---|---|---|
^ | Start of string or line | Anchor both ends for strict validation. | |
$ | End of string or line | Useful for full-string matches. | |
\b / \B | Word boundary / non-boundary | Match standalone keywords. | |
\A / \Z | Absolute start / end | Some engines support these outside JS. |
Character Classes and Groups
Build expressive token classes.
| Pattern | Meaning | Usage | Copy |
|---|---|---|---|
. | Any char except newline | Use dotall (s) to include newlines. | |
[abc] | Character set | Use ranges such as [a-zA-Z]. | |
\d \w \s | Digit, word char, whitespace | Uppercase forms negate classes. | |
(?:...) | Non-capturing group | Groups without backreferences. |
Quantifiers
Define repetition counts.
| Pattern | Meaning | Usage | Copy |
|---|---|---|---|
* | 0 or more | Use *? for lazy matching. | |
+ | 1 or more | Required repeated token. | |
? | 0 or 1 | Optional token. | |
{min,max} | Explicit bounds | Example: {8,} for minimum length. |
Lookarounds and References
Assert context without consuming characters.
| Pattern | Meaning | Usage | Copy |
|---|---|---|---|
(?=...) | Positive lookahead | Ensure next pattern exists. | |
(?!...) | Negative lookahead | Ensure next pattern does not exist. | |
(?<=...) | Positive lookbehind | Match text preceded by pattern. | |
\1 \2 | Backreferences | Reuse captured groups. |
Copy-ready Patterns
Common starter expressions.
| Pattern | Meaning | Usage | Copy |
|---|---|---|---|
^[a-z0-9_-]{3,16}$ | Username (3-16 chars) | Allows letters, digits, underscore, hyphen. | |
^\+?[0-9\s-]{7,}$ | Flexible phone | Optional plus, spaces, dashes. | |
^[\w.-]+@[\w.-]+\.[a-z]{2,}$ | Email-like string | Lightweight client-side validation. | |
^https?:\/\/[\w.-]+ | HTTP/HTTPS URL | Fast scheme + domain check. |
ADVERT
ADVERT