DevBolt

Regex Cheat Sheet & Quick Reference

A quick reference for regular expression syntax. Test any pattern from this cheat sheet in the regex tester above with real-time match highlighting.

← Back to tools

Regex Tester

Test regular expressions in real time with match highlighting and capture groups.

//g

Matches (0)

Enter a pattern and test string to see matches

Character classes

\d — digit (0-9), \D — non-digit, \w — word character (a-z, A-Z, 0-9, _), \W — non-word character, \s — whitespace (space, tab, newline), \S — non-whitespace, . — any character (except newline), [abc] — character set (a, b, or c), [^abc] — negated set (not a, b, or c), [a-z] — range (a through z).

Quantifiers

* — zero or more, + — one or more, ? — zero or one (optional), {3} — exactly 3, {3,} — 3 or more, {3,5} — between 3 and 5. By default quantifiers are greedy (match as much as possible). Add ? for lazy matching: *?, +?, ?? (match as little as possible).

Anchors and groups

^ — start of string, $ — end of string, \b — word boundary. Groups: (abc) — capturing group, (?:abc) — non-capturing group, (?=abc) — positive lookahead, (?!abc) — negative lookahead, (?<=abc) — positive lookbehind, (?<!abc) — negative lookbehind. Backreferences: \1, \2 refer to captured groups.

Frequently Asked Questions

What does \b mean in regex?

\b matches a word boundary — the position between a word character (\w) and a non-word character. For example, \bcat\b matches "cat" in "the cat sat" but not in "scatter".

What is the difference between * and + in regex?

* matches zero or more occurrences (the preceding element is optional). + matches one or more (at least one occurrence required). For example, a* matches "" and "aaa", while a+ matches "a" and "aaa" but not "".