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
- Type a pattern without the surrounding slashes, or paste a full literal such as
/^\d{4}-\d{2}$/gmand the flags are detected automatically. - Toggle flags:
gfor all matches,ito ignore case,mfor per-line anchors,sso.matches newlines,u/vfor Unicode,yfor sticky anddfor group indices. - Enter or paste test text. Matches are highlighted in alternating colours and listed with their capture groups below.
- Tick Preview a replacement to try a replacement string with
$1,$<name>or$&and copy the result. - Copy the finished pattern as a
/literal/or as anew 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/2026Regex 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.