Skip to content

Regex Cheatsheet

Interactive regex syntax reference with descriptions, examples, and a try-it-live tester for each pattern.

Regex Cheatsheet tool

Loading...

Example

Input: Word Boundary \bcat\b, tried live on the text "the cat sat in concatenate"

Result: 1 match: the standalone word "cat". The "cat" inside "concatenate" is not matched

\b matches the position between a word character and a non-word character, so the pattern only finds cat as a whole word.

Core Regex Tokens

TokenMeaningExampleMatches
.Any character except newlinea.cabc, a1c, a-c
\dDigit (0-9)\d+42, 007, 2026
\wLetter, digit or underscore\w+hello_42
\sWhitespacea\sba b
[abc]Any one of the listed characters[aeiou]a, e, i, o, u
[^abc]Any character not listed[^0-9]a, !, space
^Start of string or line^HelloHello world
$End of string or lineworld$Hello world
\bWord boundary\bcat\bthe cat sat
*Zero or moreab*cac, abc, abbc
+One or moreab+cabc, abbc
?Zero or onecolou?rcolor, colour
{n,m}Between n and m times\d{2,4}42, 123, 1234
(abc)Capturing group(\d{3})-(\d{4})555-1234
a|bEither sidecat|dogcat or dog

Examples taken from the entries in this cheatsheet.

  1. Browse regex syntax elements by category (character classes, anchors, quantifiers, groups and lookarounds, flags), or type in the search box to filter them.
  2. Click on any pattern element to see its description, an example pattern, and sample text it matches.
  3. Use the inline mini-tester for each element to type a test string and see matches highlighted in real time.
  4. Try different test strings in the mini-tester, including ones that should not match, to understand exactly how the syntax works.
  5. Scroll to the "Common Patterns" section to find ready-to-use regexes for emails, URLs, phone numbers, and more.
  6. Copy any pattern or example using the copy button to paste it directly into your code.

Regex Syntax Cheat Sheet with Live Examples

This regex cheatsheet explains the building blocks of regular expressions one at a time. Each has an example and a small live tester. There are 46 entries in six groups: character classes, anchors, quantifiers, groups and references, flags, and common patterns.

A regular expression is a pattern for finding text. Most of it is ordinary characters that match themselves, plus a few symbols with special meaning. \d means any digit, + means one or more of the item before it, and ^ ties the match to the start. Together, ^\d+ matches the digits at the start of a line. Learning the pieces one by one, as they are laid out here, is much easier than decoding a finished pattern.

Open any entry to see its description, an example pattern and sample text it matches. Then type your own text into its mini tester, and matches are highlighted and counted as you type. The tester runs the example rather than the placeholder, so for {n} it tries \d{3}. Try text that should fail too. Seeing why \bcat\b skips the cat inside concatenate teaches more than a match does. The pattern and the example each have a copy button. The search box at the top filters entries by pattern, name or description.

The syntax is JavaScript's, which most languages share for the basics. The Common Patterns group has starting points for emails, URLs, E.164 phone numbers, IPv4 addresses, ISO dates, hex colors, prices and strong passwords, with their limits noted. When you are ready to build a full pattern against real data, move to the Regex Tester.

Sources

Frequently Asked Questions

It covers JavaScript (ECMAScript) regular expressions, and the mini testers run in your browser's JavaScript engine. The core syntax is the same in Python, Java, PHP and .NET. Details differ, such as named groups, which Python writes as (?P<name>...), and flags, which are passed differently in each language.
Greedy quantifiers such as * and + take as much text as they can. Lazy versions, *? and +?, take as little as possible. On the text "a" "b", the pattern ".*" matches everything from the first quote to the last, while ".*?" matches "a" and "b" separately. Use lazy quantifiers when you want the shortest match.
Put a backslash in front of it. \. matches a literal dot, \( a bracket and \$ a dollar sign. The characters that need this are . * + ? ^ $ { } ( ) [ ] | and the backslash itself. Inside square brackets most of them lose their special meaning, so [.] also matches a dot.
They check what comes before or after a spot without including it in the match. \d+(?= dollars) matches 100 in 100 dollars but not the word dollars. (?<=\$)\d+ matches 50 in $50 without the dollar sign. The negative forms, (?!...) and (?<!...), require the text to be absent. All four work in current browsers.
The cheatsheet teaches one piece of syntax at a time, each with its own small tester. The Regex Tester is for building a complete pattern: it has flag toggles, capture group details and a list of every match. Learn a piece here, then combine the pieces in the tester.

Related Tools

Regex Tester

Test regular expressions with real-time match highlighting, group capture display, and a pattern library.

Developer Tools

Git Cheatsheet

Searchable interactive Git command reference organized by workflow - branching, merging, rebasing, and more.

DevOps Tools

Find and Replace

Find and replace text with regular expressions, capture groups, case-sensitive matching, and a live match count.

Text and Writing

Text Diff and Compare Tool

Compare two blocks of text side by side and highlight the differences. Find additions, deletions, and changes instantly.

Text and Writing

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools