Skip to content

Test regular expressions with real-time match highlighting. See capture groups, named groups, and match positions.

//
Flags:
/…/g
Test String
Enter a pattern and test string above
Ctrl+Shift+CCopy matchesResults update as you type

Share this tool

Found it useful? Help a fellow developer discover it.

https://developertoolkit.dev/tools/regex-tester

How to use the Regex Tester

  1. Type your pattern in the /pattern/ field. Matches update instantly as you type.
  2. Toggle flags using the letter buttons next to the pattern: g (global), i (case-insensitive), m (multiline), s (dot-all), u (unicode).
  3. Paste your test string in the editor below the pattern.
  4. The Match Preview section highlights each match inline with distinct colors.
  5. The Matcheslist shows each match's value, position, length, and all capture groups (numbered and named).

JavaScript regex flags explained

FlagNameEffect
gGlobalFind all matches in the string, not just the first one. Without this flag, only the first match is returned.
iCase-insensitiveMake the pattern match regardless of letter case. /hello/i matches "Hello", "HELLO", "hElLo".
mMultiline^ and $ match the start and end of each line (not just the whole string). Essential when testing multi-line input.
sDot-allMakes . match any character including newlines (\n). Without this flag, . only matches non-newline characters.
uUnicodeEnable full Unicode matching. Required for patterns that use Unicode property escapes (\p{...}) or match astral plane characters (emoji, etc.).

Regex cheat sheet

A quick reference for JavaScript regular expression syntax. Paste any token into the pattern field above to see what it matches.

Character classes

.Any character except a line break (any character with the s flag)
\dA digit, 0 to 9
\DAny character that is not a digit
\wA word character: letter, digit, or underscore
\WAny character that is not a word character
\sWhitespace: space, tab, line break
\SAny character that is not whitespace
[abc]Any one of a, b, or c
[^abc]Any character except a, b, or c
[a-z]Any character in the range a to z

Anchors and boundaries

^Start of the string (start of each line with the m flag)
$End of the string (end of each line with the m flag)
\bWord boundary
\BNot a word boundary

Quantifiers

*Zero or more of the previous token
+One or more of the previous token
?Zero or one of the previous token
{3}Exactly 3
{3,}3 or more
{3,5}Between 3 and 5
*? +? ??Lazy versions: match as few characters as possible

Groups and lookarounds

(abc)Capture group
(?<name>abc)Named capture group
(?:abc)Non-capturing group
a|bMatch a or b
\1Backreference to capture group 1
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Escaped characters

\. \* \+ \?Match a literal dot, asterisk, plus, or question mark
\( \) \[ \]Match literal brackets
\t \n \rTab, line feed, carriage return
\u00e9A Unicode code point by hex value

Common regex patterns

Email address

/[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/g

Matches common email addresses. Not RFC 5321 compliant but covers 99% of real-world emails.

IPv4 address

/\b(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g

Matches valid IPv4 addresses (0.0.0.0 – 255.255.255.255).

UUID v4

/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gi

Matches UUID v4 strings in standard hyphenated format.

ISO 8601 date

/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g

Matches dates in YYYY-MM-DD format (e.g. 2026-03-16).

Hex color

/#(?:[0-9a-fA-F]{3}){1,2}\b/g

Matches 3 or 6-digit hex color codes (#fff or #ffffff).

JWT token

/[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g

Matches JWT tokens (three Base64URL segments separated by dots).

Frequently Asked Questions

How do I test a regex pattern online?

Type your pattern in the /pattern/ field and paste your test string in the editor below it. Matches are highlighted in real time as you type. Toggle flags (g, i, m, s, u) using the letter buttons next to the pattern field. The Matches list shows each match value, position, length, and all capture groups.

What is the difference between regex and glob patterns?

Regex (regular expressions) is a powerful pattern language for matching text based on characters, classes, quantifiers, and anchors. Glob patterns (used in file systems and shell commands) are simpler, using only * (any characters), ? (one character), and [...] (character sets). A regex like ^src/.*\.tsx$ is the glob equivalent of src/**/*.tsx. Globs cannot express groups, alternation, or lookaheads.

Why does my pattern with .* match the entire string?

.* is greedy, meaning it matches as many characters as possible. Use .*? for a non-greedy (lazy) match, which stops at the first opportunity. For example, <.*> matches the whole string "<b>text</b>", while <.*?> matches only "<b>".

What is the difference between ^ and $ in multiline mode?

Without the m flag, ^ matches the very start of the string and $ matches the very end. With the m flag, ^ matches the start of each line and $ matches the end of each line. This is essential when you want to match patterns at line boundaries in multi-line text.

How do I use named capture groups?

Use (?<name>...) syntax. For example, (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) captures the parts of a date as named groups year, month, and day. This tool shows named group values in the match list alongside numbered groups.

What causes catastrophic backtracking?

Patterns like (a+)+ on long strings can cause exponential time complexity as the regex engine tries every possible way to match. Avoid nested quantifiers on overlapping character classes. If your test string is large and the page becomes unresponsive, this is the likely cause. This tester has a 10,000-match safety limit to prevent hangs.

Does this tester use JavaScript regex syntax?

Yes. It uses JavaScript's built-in RegExp engine running in your browser. Syntax and behavior may differ from PCRE (PHP, Python), POSIX (grep), or .NET regex. Most common patterns are compatible, but features like variable-length lookbehind assertions (supported in Python but not all JS engines) may behave differently.

How do I match a specific word but not as part of a longer word?

Use word boundary anchors: \b before and after the word. For example, \bcat\b matches "cat" in "the cat sat" but not in "caterpillar" or "concatenate". Without the anchors, cat would match the substring in all three. Add the g flag to find all occurrences in a string.

What is the difference between a regex tester and a regex validator?

There isn't a technical difference, they describe the same task from two angles. 'Validator' emphasizes checking whether a pattern matches expected input correctly (for example, validating an email format). 'Tester' or 'matcher' emphasizes seeing what a pattern matches against sample text. This tool does both: type a pattern, paste representative input, and confirm it matches (or rejects) what you expect.

Related Tools

From the Blog

The Regex That Took Down Cloudflare. What ReDoS Is and How to Write Regular Expressions That Do Not Kill Your Server

A case study on catastrophic backtracking and the 2019 Cloudflare outage, used as a lens to teach developers how to write safe, performant regular expressions.

Read article