Regex Tester
Live matches, capture groups and replace preview — safe from runaway patterns.
Type the pattern without the surrounding slashes. Pasting a literal such as /\d+/gi fills in the flags too.
What do the flags do?
-
gglobal - Find every match instead of stopping after the first one.
-
iignore case - Upper- and lower-case letters match each other.
-
mmultiline - ^ and $ also match at the start and end of every line.
-
sdot all - The dot (.) also matches line breaks.
-
uunicode - Match whole Unicode code points; enables \p{…} and \u{…} and stricter syntax.
-
vunicode sets - Everything u does, plus set operations (&&, --) and nested classes inside […]. Cannot be combined with u.
-
ysticky - Each match must start exactly where the previous one ended (the first at position 0).
-
dindices - Also report the start and end position of every capture group.
Matches
Enter a pattern and some text.
Matching…
Match details
| # | Match | Position | Groups |
|---|
Matches appear here with their position (start–end, counted in UTF-16 code units like JavaScript) and capture groups. Select a position to highlight it in the test string.
Replace
$1…$99 numbered group · $<name> named group · $& whole match · $$ a literal $. Without the g flag only the first match is replaced.
Use it in JavaScript
/(?:)/g new RegExp("", "g") About the Regex Tester
Build and debug regular expressions against your own text. Matches are highlighted as you type, every match is listed with its position and its capture groups (numbered and named), and the replace preview shows exactly what String.prototype.replace would return.
The tester uses your browser's own JavaScript regex engine — the same one that runs the scripts on web pages — and supports every flag, including d (group indices) and v (Unicode sets). Matching runs in a background worker with a 1.5-second limit, so a runaway pattern is stopped with an explanation instead of freezing the page.
How to use it
- Type the pattern without the surrounding slashes, for example
\d{3}-\d{4}. You can also paste a literal such as/\d+/gi— the pattern and flags are filled in separately. - Choose the flags. Turn on g to find every match; without it JavaScript stops after the first one.
- Paste the text to search into Test string. Matches are highlighted immediately, and Match details lists each match with its position and groups. Select a position to jump to that match.
- To rewrite text, enter a Replacement using
$1,$<name>or$&, then copy the result or the ready-made JavaScript code.
Examples
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Flags: g
Text: Invoice 2026-10-02, due 2026-11-01
Replacement: $<day>/$<month>/$<year>Invoice 02/10/2026, due 01/11/2026
Pattern: \b(\w+)\s+\1\b Flags: gi Text: This is is a test of the the finder Replacement: $1
This is a test of the finder
\1 is a back-reference: it matches the same text that group 1 captured.
Common uses
- Writing validation patterns for forms (PIN codes, phone numbers, IDs) and checking them against real and invalid samples.
- Extracting values from logs and copying all matches at once.
- Preparing search-and-replace rules for an editor, a build script or a database migration.
- Learning regex syntax by experimenting with the examples and the cheat sheet below.
Cheat sheet: characters and classes
.any character except line breaks (any character at all with thesflag)\da digit 0–9 ·\Dany non-digit\wa letter, digit or underscore (ASCII only) ·\Wanything else\swhitespace, including tabs, line breaks and Unicode spaces ·\Sanything else[abc]one of a, b or c ·[^abc]any other character ·[a-z0-9]ranges\ttab ·\nline feed ·\rcarriage return ·\u00e9a UTF-16 code unit ·\u{1F600}a code point (needsuorv)\p{L}any letter,\p{Nd}any decimal digit,\p{Script=Devanagari}— Unicode properties (needuorv)\.\*\(\[\\— a backslash makes a special character match itself
Cheat sheet: anchors, quantifiers and groups
^start and$end of the text (of every line with themflag) ·\bword boundary ·\Bnot a word boundary*zero or more ·+one or more ·?optional ·{3}exactly 3 ·{2,}2 or more ·{2,5}2 to 5- Add
?after a quantifier to make it lazy (match as little as possible):.*?,+?,{2,5}? (abc)capturing group ·(?:abc)group without capturing ·(?<name>abc)named group\1back-reference to group 1 ·\k<name>back-reference to a named group ·a|beither a or b(?=x)followed by x ·(?!x)not followed by x ·(?<=x)preceded by x ·(?<!x)not preceded by x
Replacement patterns
$1…$99the text captured by a numbered group$<name>the text captured by a named group$&the whole match$'the text after the match (a dollar sign followed by a backtick inserts the text before it)$$a literal dollar sign
These are the rules of JavaScript's String.prototype.replace, documented in the ECMAScript specification. A group that did not take part in the match is replaced with nothing.
Why slow patterns are stopped
JavaScript regex engines work by backtracking: when part of a pattern fails, the engine goes back and tries another way. Nested quantifiers such as (a+)+$ or (\w*)* can split the same text in exponentially many ways — with (a+)+$, every extra letter roughly doubles the work. On a normal web page this freezes the tab.
Here matching runs in a separate background worker. If it has not finished after 1.5 seconds the worker is stopped and you get an explanation instead. To fix such a pattern, avoid nesting quantifiers over the same characters, make alternatives mutually exclusive, prefer specific classes like [^"]* over .*, and anchor the pattern where you can.
JavaScript compared with other regex flavours
\dand\wmatch ASCII characters only, even with theuflag. Use\p{Nd}or\p{L}withufor other scripts.- Named groups use
(?<name>…). Python's(?P<name>…)form is not accepted. - There are no possessive quantifiers (
a++), atomic groups ((?>…)), recursion or conditionals, as found in PCRE. \A,\Zand\zdo not exist; use^and$without themflag.- Inline flags such as
(?i)at the start of a pattern are not supported — use the flag buttons. - Lookbehind (
(?<=…),(?<!…)) is supported, including variable-length lookbehind.
Limitations
- Results come from the JavaScript engine of your browser. Patterns written for PHP (PCRE), Python, Java, .NET or Go may need changes, as listed above.
- Up to 5,000 matches are highlighted (within the first 300,000 characters of the text) and the first 500 are listed in the table. Counting stops at 100,000 matches; Copy matches copies every match counted.
- Positions are counted in UTF-16 code units, as JavaScript does, so most emoji count as two.
- Matching is stopped after 1.5 seconds to protect the page.
Privacy
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
Which regex flavour does this tester use?
JavaScript (ECMAScript), using the regex engine built into your browser. The behaviour is the same as RegExp, String.prototype.match and String.prototype.replace in your own scripts. Other languages differ in some advanced features — see the comparison above.
Why do I only get one match?
Turn on the g (global) flag. Without it JavaScript stops after the first match, exactly as text.match(regex) and text.replace(regex, …) do in code.
Why did the tester stop my pattern?
It took longer than 1.5 seconds, which almost always means catastrophic backtracking from nested or overlapping quantifiers. The same pattern would freeze a web page or block a Node.js server, so it is worth fixing — see "Why slow patterns are stopped" above.
Do I need to escape forward slashes?
Not in the pattern box. A slash only needs escaping inside a regex literal in code (/a\/b/). The Use it in JavaScript box adds the escapes for you.
What is the difference between the u and v flags?
Both make the pattern work with whole Unicode code points and enable \p{…}. The newer v flag adds set operations inside character classes — subtraction [\p{L}--[a-z]], intersection && and nested classes — and properties of strings such as \p{RGI_Emoji}. It also requires a few more characters to be escaped inside classes. The two flags cannot be combined.
Is my text sent anywhere?
No. The pattern and the text stay in your browser; matching happens on your device, even offline.