Printable reference
Regex CheatSheet
Every common regex symbol with a plain-English meaning, a small example, and which of the 8 supported languages can use it. The “Works in” column comes from the same feature table that powers the compatibility checker. Use the print button to save it as a PDF.
49 entries
Anchors
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
^ | Start of the string (or line with the m flag) | ^Hello→ “Hello” at the start | All 8 languages |
$ | End of the string (or line with the m flag) | end$→ “end” at the end | All 8 languages |
\b | Word boundary | \bcat\b→ “cat” but not “category” | All 8 languages |
\B | Not a word boundary | \Bcat→ “cat” inside “bobcat” | All 8 languages |
\A | Very start of the string | \AID→ “ID” only at the very start | Not in: JavaScript |
\z | Very end of the stringPython uses \Z | done\z→ “done” only at the very end | Not in: JavaScript, Python |
Character classes
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
. | Any character except newline (any at all with s) | a.c→ abc, a-c, a7c | All 8 languages |
\d | A digit | \d\d→ 42 | All 8 languages |
\D | Not a digit | \D+→ abc | All 8 languages |
\w | Word character: letter, digit or _ | \w+→ user_01 | All 8 languages |
\W | Not a word character | \W→ @ or space | All 8 languages |
\s | Whitespace (space, tab, newline) | a\sb→ a b | All 8 languages |
\S | Not whitespace | \S+→ word | All 8 languages |
[abc] | One of a, b or c | gr[ae]y→ gray, grey | All 8 languages |
[^abc] | Any character except a, b, c | [^0-9]→ x | All 8 languages |
[a-z] | A character in the range | [A-Z]{2}→ PK | All 8 languages |
\p{L} | Any Unicode letter | \p{L}+→ café, Ωmega | Not in: PythonLimited: JavaScript, PHP |
Quantifiers
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
* | Zero or more | ab*c→ ac, abc, abbc | All 8 languages |
+ | One or more | \d+→ 7, 2026 | All 8 languages |
? | Zero or one (optional) | colou?r→ color, colour | All 8 languages |
{n} | Exactly n times | \d{4}→ 2026 | All 8 languages |
{n,} | n or more times | \w{3,}→ abc, abcdef | All 8 languages |
{n,m} | Between n and m times | \d{2,4}→ 12, 1234 | All 8 languages |
*? +? ?? | Lazy: as few as possible | <.+?>→ <b> not <b>…</b> | All 8 languages |
*+ ++ ?+ | Possessive: never give back | \d++→ digits, no backtracking | Not in: JavaScript, Go, RustLimited: Python, C# |
Groups
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
(…) | Capturing group | (\d+)-(\d+)→ 12-34 → groups 12, 34 | All 8 languages |
(?:…) | Non-capturing group | (?:ab)+→ abab | All 8 languages |
(?<name>…) | Named group (Python: (?P<name>…)) | (?<year>\d{4})→ 2026 → year | Limited: Python, Java |
\1 | Backreference to group 1 | (\w)\1→ ll in hello | Not in: Go, Rust |
\k<name> | Named backreference (Python: (?P=name)) | (?<c>\w)\k<c>→ oo in book | Not in: Go, RustLimited: Python |
a|b | Alternation: a or b | cat|dog→ cat, dog | All 8 languages |
(?>…) | Atomic group | (?>a+)b→ aab | Not in: JavaScript, Go, RustLimited: Python, C# |
Lookarounds
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
(?=…) | Lookahead: followed by | \d+(?=px)→ 12 in 12px | Not in: Go, Rust |
(?!…) | Negative lookahead: not followed by | \d+(?!px)→ 12 in 12em | Not in: Go, Rust |
(?<=…) | Lookbehind: preceded by | (?<=\$)\d+→ 50 in $50 | Not in: Go, RustLimited: Python, PHP, Java, Ruby |
(?<!…) | Negative lookbehind: not preceded by | (?<!\$)\d+→ 50 in €50 | Not in: Go, RustLimited: Python, PHP, Java, Ruby |
Flags
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
i | Ignore case | /hello/i→ HeLLo | All 8 languages |
g | Global: all matches (other languages use findall/scan APIs) | /\d/g→ every digit | All 8 languages |
m | Multiline: ^ and $ per line (always on in Ruby) | /^-/m→ - at each line start | All 8 languages |
s | Dotall: . matches newline (Ruby writes it as m) | /a.b/s→ a\nb | All 8 languages |
u | Unicode mode (JavaScript, PHP) | /\p{L}/u→ é | All 8 languages |
x | Extended: ignore whitespace and allow comments | (?x) \d+ # digits→ 123 | Not in: JavaScript, Go |
y | Sticky: match at lastIndex only | /foo/y→ foo at the current position | Not in: Python, PHP, Java, Go, C#, Rust, Ruby |
(?i) | Inline flag inside the pattern | (?i)hello→ HELLO | Not in: JavaScript |
Escapes
| Symbol | Meaning | Example | Works in |
|---|---|---|---|
\. | A literal dot (escape any special character) | example\.com→ example.com | All 8 languages |
\n \t \r | Newline, tab, carriage return | a\tb→ a<tab>b | All 8 languages |
\xhh | Character by hex code | \x41→ A | All 8 languages |
\uhhhh | Character by Unicode code (Go/Rust/Ruby: \x{…} or \u{…}) | \u00e9→ é | Not in: PHP, Go, Rust |
\\ | A literal backslash | C:\\temp→ C:\temp | All 8 languages |
Language feature table
| Feature | JavaScript | Python | PHP | Java | Go | C# | Rust | Ruby |
|---|---|---|---|---|---|---|---|---|
Lookahead (?= ) (?! ) | ✓ | ✓ | ✓ | ✓ | ✗ | ✓ | ✗ | ✓ |
Lookbehind (?<= ) (?<! ) | ✓ (ES2018) | fixed width only | each alternative fixed | bounded | ✗ | ✓ variable | ✗ | limited |
Backreference \1 | ✓ | ✓ | ✓ | ✓ | ✗ | ✓ | ✗ | ✓ |
Named group (?<name> ) | (?<n>) | (?P<n>) only | both | (?<n>) letters/digits only | (?P<n>), (?<n>) 1.22+ | (?<n>) | (?P<n>), (?<n>) 1.9+ | (?<n>) |
Named backreference \k<name> | \k<n> | (?P=n) | \k<n>, (?P=n) | \k<n> | — | \k<n> | — | \k<n> |
Possessive / atomic a++ (?>a) | ✗ | 3.11+ | ✓ | ✓ | ✗ | atomic (?>) only | ✗ | ✓ |
Unicode property \p{L} \p{L} | needs u | ✗ (re) | needs u | ✓ | ✓ | ✓ | ✓ | ✓ |
Inline flags (?i) | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Extended x flag x | ✗ | ✓ | ✓ | ✓ | ✗ | ✓ | ✓ | ✓ |
Sticky y flag y | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
\d and \w are ASCII-only by default in JavaScript, Go and Java, but Unicode-aware by default in Python, .NET and Rust.
New to regex? Start with Lesson 1: What is Regex, or see why engines differ in Lesson 28.