Developer Tools

Regex Tester

Test regular expressions with real-time matching and capture group inspection.

Presets:
//g
Test Text338 chars
Highlighted matches
Contact [email protected] or [email protected] Servers: 192.168.1.10, 10.0.0.254 and 999.1.1.1 (invalid) Release date: 2026-11-03, hotfix 2026-12-01. Brand color #3b82f6, accent #fff. Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions Request id 3f2b8c1e-9d4a-4c7b-8e21-5a6f0b9c2d13 · 正则表达式测试
Matches (0)

No matches.

Regex cheat sheet
.
Any character except newline
\d \w \s
Digit, word character, whitespace
\D \W \S
Not digit / word / whitespace
[abc] [^abc] [a-z]
Character set, negated set, range
^ $
Start / end of input (or line with m)
\b
Word boundary
* + ?
0 or more, 1 or more, 0 or 1
{n} {n,} {n,m}
Exactly n, at least n, between n and m
*? +?
Lazy (match as little as possible)
(abc)
Capturing group, referenced as $1
(?<name>abc)
Named group, referenced as $<name>
(?:abc)
Group without capturing
a|b
Either a or b
(?=x) (?!x)
Followed by x / not followed by x
(?<=x) (?<!x)
Preceded by x / not preceded by x
\p{L} \p{Script=Han}
Unicode property (needs the u flag)

About this tool

A regular expression (regex) is a compact pattern that describes text: "four digits, a dash, two digits", "anything that looks like an email address", "a line that ends with spaces". Regexes power search-and-replace in editors, input validation in forms, log parsing, and data cleanup scripts. They are also notoriously easy to get subtly wrong, which is why testing a pattern against real sample text before shipping it is worth the minute it takes.

This tester uses your browser's own JavaScript regex engine, so the results match exactly what your JavaScript or TypeScript code will do. Matching runs in a background worker with a time limit: a pattern that would freeze a page with catastrophic backtracking is stopped and reported instead.

How to use Regex Tester

  1. Type a pattern between the slashes, or start from a preset such as Email, IPv4 or Date. Patterns are written without the surrounding /.../ delimiters.
  2. Toggle flags: g finds all matches instead of the first, i ignores case, m makes ^ and $ match at every line, s lets . match newlines, u enables full Unicode and \p{...} properties, y anchors each match at the current position.
  3. Paste your test text. Matches are highlighted on the right and listed below with their position and every capture group, including named groups.
  4. Turn on Replace to preview a search-and-replace. Use $1, $2 for numbered groups, $<name> for named groups and $& for the whole match.
  5. Copy the list of matches or the replaced text when you are done. Open the cheat sheet at the bottom for a quick syntax reminder.

Examples

Reformat dates with named groups

Input
Pattern: (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})
Replace: $<d>/$<m>/$<y>
Text: Due 2026-11-03
Result
Due 03/11/2026

Find trailing whitespace on every line

Input
Pattern: [ \t]+$
Flags: g m
Result
Highlights the spaces at the end of each line; replace with an empty string to clean them up.

Without the m flag, $ only matches at the very end of the text.

Match Chinese characters

Input
Pattern: \p{Script=Han}+
Flags: g u
Text: 价格 price 99 元
Result
Matches: 价格, 元

Avoiding catastrophic backtracking

JavaScript uses a backtracking regex engine. Patterns with nested or overlapping quantifiers, such as (a+)+$ or (\w+\s?)*$, can take exponential time on inputs that almost match. In production this is a denial-of-service risk (ReDoS): one crafted string can block a Node.js server.

  • Avoid quantifiers inside quantified groups when both can match the same characters: (a+)+ → a+.
  • Make alternatives mutually exclusive: (\d|\d\d)+ → \d+.
  • Prefer specific character classes over .* where possible: "[^"]*" instead of ".*".
  • If this tool reports a timeout, your pattern has this problem; simplify it before using it on user input.

Greedy vs. lazy quantifiers

Quantifiers like * and + are greedy: they match as much as possible and then give back characters if the rest of the pattern fails. Adding ? makes them lazy. On the text <b>one</b><b>two</b>, the pattern <b>.*</b> matches the whole string, while <b>.*?</b> matches each tag pair separately.

Frequently asked questions

Everything you need to know about this tool and data security.

Will a pattern tested here behave the same in Python, Java or Go?

The core syntax (classes, quantifiers, groups, anchors) is shared, but details differ: named groups are (?P<name>...) in Python, Go has no lookbehind, and Unicode property syntax varies. This tool is exact for JavaScript and TypeScript; for other languages, double-check advanced features.

Why does my pattern only find one match?

Without the g (global) flag, JavaScript stops at the first match. Turn on g to list every match in the text.

How do I match a literal dot, slash or bracket?

Escape special characters with a backslash: \. matches a dot, \( a parenthesis, \[ a bracket and \\ a backslash. A forward slash does not need escaping here because you type the pattern without delimiters.

Is there a limit on the number of matches?

The tester collects up to 5,000 matches and highlights the first 2,000 to keep the page fast. The match count shows a + when the limit is reached.

Is my data safe when using this tool?

Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.