Regex Tester

Test JavaScript regular expressions live with match highlighting, capture groups, replace preview and a library of common patterns.

Runs in your browser

Regular expression

Tip: paste a literal like /^\d+$/gm and the flags are picked up automatically.

Test string

Highlighted matches

Matches are highlighted here.

Replace

Uses String.prototype.replace with the current flags (add g to replace every match).

Common patterns

  • Email (pragmatic)

    Covers real-world addresses; full RFC 5322 validation is impractical with a regex. Confirm by sending an email.

  • URL (http/https)

    Matches absolute http(s) URLs with a domain name. Use the URL constructor for strict validation.

  • IPv4 address

    Each octet is limited to 0–255.

  • IPv6 address (simplified)

    One address per line. Handles :: compression; does not cover zone IDs (%eth0) or embedded IPv4.

  • Hex color

    Matches #rgb, #rgba, #rrggbb and #rrggbbaa.

  • Slug

    Lowercase letters and digits separated by single hyphens, one per line.

  • Date (YYYY-MM-DD)

    Checks ranges per field but not month lengths (2026-02-31 passes). Uses named groups.

  • Time (24-hour)

    HH:MM with optional :SS.

  • Phone (E.164)

    International format: +, country code, up to 15 digits in total, no spaces.

  • US ZIP code

    Five-digit ZIP or ZIP+4.

  • UUID

    RFC 9562 versions 1–8 with the standard variant.

  • HTML tag

    Group 1 is the tag name. Fine for quick searches; use a DOM parser to process HTML.

  • WordPress shortcode

    Same structure as WordPress get_shortcode_regex(): 2 = tag, 3 = attributes, 5 = content.

  • Semantic version

    The official pattern from semver.org, one version per line.

Quick reference

Characters
.Any character except line breaks (with the s flag, any character)
\d \DDigit 0–9 / not a digit
\w \WWord character [A-Za-z0-9_] / not a word character
\s \SWhitespace / not whitespace
[abc] [^abc]Any of a, b, c / anything except a, b, c
[a-z]Character range
\p{L} \p{Lu}Unicode letter / uppercase letter (u or v flag)
\t \n \rTab, line feed, carriage return
\. \\ \/Escaped literal dot, backslash, slash
Anchors
^ $Start / end of input (of each line with the m flag)
\b \BWord boundary / not a word boundary
Quantifiers
* + ?0 or more / 1 or more / 0 or 1
{3} {2,} {2,5}Exactly 3 / 2 or more / between 2 and 5
*? +? ??Lazy versions: match as few as possible
Groups & lookaround
(abc)Capturing group, referenced as $1 or \1
(?<name>abc)Named group, referenced as $<name> or \k<name>
(?:abc)Non-capturing group
a|bAlternation: a or b
(?=abc) (?!abc)Positive / negative lookahead
(?<=abc) (?<!abc)Positive / negative lookbehind
Replacement
$&The whole match
$1 … $99Capture group by number
$<name>Named capture group
$` $'Text before / after the match
$$A literal dollar sign

What is a regex tester?

A regular expression (regex) is a compact pattern language for finding, validating and transforming text — from checking that a form field looks like an email address to rewriting thousands of URLs in a database export. Regexes are powerful but easy to get subtly wrong, so testing them against real sample text before they reach production code is essential.

This tester uses your browser’s own JavaScript RegExp engine, so results match exactly what String.prototype.match, matchAll, replace and RegExp.prototype.test will do in Node.js and the browser. Every match is highlighted as you type, and the details table lists each match’s position, numbered capture groups and named groups.

Matching runs in a Web Worker with a two-second time limit, so a pattern with catastrophic backtracking — like (a+)+$ against a long string of as — is stopped instead of freezing the page. Your pattern and text never leave your device.

How to use the Regex Tester

  1. Type a pattern without the surrounding slashes, or paste a full literal such as /^\d{4}-\d{2}$/gm and the flags are detected automatically.
  2. Toggle flags: g for all matches, i to ignore case, m for per-line anchors, s so . matches newlines, u/v for Unicode, y for sticky and d for group indices.
  3. Enter or paste test text. Matches are highlighted in alternating colours and listed with their capture groups below.
  4. Tick Preview a replacement to try a replacement string with $1, $<name> or $& and copy the result.
  5. Copy the finished pattern as a /literal/ or as a new RegExp() call, or start from one of the common patterns.

Example

Reformat dates from YYYY-MM-DD to DD/MM/YYYY with named groups and the g flag:

Pattern:      (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})
Replacement:  $<d>/$<m>/$<y>

Input:   Published 2026-10-01, updated 2026-12-24
Result:  Published 01/10/2026, updated 24/12/2026

Regex flavours: JavaScript vs PHP and others

Most syntax is shared between JavaScript, PHP (PCRE), Python and Java, but there are differences. PHP patterns need delimiters, as in preg_match( '/^\d+$/', $value ), and support possessive quantifiers and atomic groups that JavaScript lacks. JavaScript has no x (extended) flag and, before the v flag, limited set operations in character classes. When porting a pattern to WordPress code, test the PHP version with representative input as well.

Avoiding catastrophic backtracking

  • Avoid nested quantifiers over the same characters, such as (a+)+, (\w*)* or (.*a){10}.
  • Prefer specific character classes to .*: "[^"]*" is faster and safer than ".*?".
  • Anchor patterns with ^ and $ when validating a whole value.
  • Never run untrusted, user-supplied patterns on a server without a timeout — this is the cause of ReDoS vulnerabilities.

Frequently Asked Questions

Which regex flavour does this tester use?

ECMAScript (JavaScript), executed by your browser. Results are identical to Node.js and other browsers for standard syntax. PCRE-only features such as possessive quantifiers, atomic groups or recursion are reported as syntax errors.

Why does my pattern only find the first match?

Without the g (global) flag, JavaScript stops after the first match — both for highlighting and for replace(). Enable g to find or replace every occurrence.

What is the difference between the u and v flags?

Both enable Unicode mode, so \p{L} and astral characters such as emoji work. The newer v flag (ES2024) adds set subtraction and intersection in classes, like [\p{L}--[a-z]], and string properties. They cannot be combined; the tester switches one off when you enable the other.

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

Escape it with a backslash: \., \/, \[. Inside a character class most characters are literal, so [.] also matches a dot.

Can I use this to search and replace text without writing a regex?

Yes — for plain-text replacements, the Find and Replace tool is simpler. To normalise whitespace or line breaks try the Text Cleaner.