Free online regex tester and visualizer. Write a JavaScript regular expression and see it drawn as an interactive diagram, explained in plain English and matched live with colour-coded capture groups. Replace, extract, unit-test and export code, no signup.
A regex tester that shows you what your pattern means
Test, debug and understand regular expressions in one place. Type a pattern and it is instantly drawn as an interactive railroad diagram, explained token by token in plain English, and run live against your text with every match and capture group colour-highlighted. Replace, extract, split, write unit tests, export working code for 9 languages and get warned about catastrophic backtracking, all inside your browser.
Most regex testers only tell you whether a pattern matched. This one also shows you why. As you type, the regular expression is parsed and drawn as a railroad diagram: a left-to-right map where every path through the diagram is a string the pattern can match. Hover any box and the matching characters light up in your pattern, and a plain-English description tells you exactly what that piece does. Move the text cursor through the pattern and the diagram follows it. Underneath, your pattern runs live against your own test text with every match highlighted and each capture group in its own colour, so you can see what matched and why at the same time.
Features
Interactive railroad diagram of any pattern: hover a box to light it up in the regex
Plain-English explanation of every token, group, quantifier and lookaround
Live match highlighting with colour-coded capture groups inside the text
Click a match to see what each group captured, right on the diagram
Syntax-coloured pattern editor that follows your cursor
All JavaScript flags: g, i, m, s, u, v (unicode sets) and y
Replace with $1, $<name>, $& and a highlighted before/after preview
Extract matches to a list with templates, unique/sort, CSV and JSON export
Split text by a regex, and unit tests that must (or must not) match
Code export for JavaScript, TypeScript, Python, PHP, Java, C#, Go, Rust and Ruby
Compatibility table: see which features break in Python, PCRE, Go or Rust
ReDoS guard: runs in a worker, stops runaway patterns and flags nested quantifiers
Library of 40 tested patterns plus a generate-from-examples builder
Clickable cheatsheet, saved patterns and shareable links, 100% in your browser
How to use Regex Tester & Visualizer
1
Enter a pattern
Type a regex (pasting /pattern/flags splits it automatically), pick one from the pattern library, or generate one from examples in the Build tab.
2
Toggle flags
Click g, i, m, s, u, v or y to change matching behaviour; hover a flag to see what it does.
3
Read the visual diagram
Hover or click any box in the railroad diagram, or switch to Explanation, to see what each part of the pattern means.
4
Test against your text
Paste text into the test string; matches and capture groups highlight live. Click a match to see each group's value on the diagram.
5
Replace, extract or test
Use Replace, Extract, Split and Unit tests to check the pattern does exactly what you need.
6
Export or share
Copy working code for your language from the Code tab, download the diagram as SVG/PNG, or copy a share link.
Common use cases
Understand a complex regex you inherited, one diagram box at a time
Debug why a regex isn't matching your data
Validate an email, URL, phone or password pattern before shipping it
Extract fields from log lines with named capture groups
Craft and preview a find-and-replace with group references
Port a JavaScript regex to Python, PHP, Go or Java
Check a pattern for catastrophic backtracking (ReDoS)
Teach or learn regular expressions with a visual explanation
Detailed guide
How to read a regex railroad diagram
Railroad (syntax) diagrams are read like a train track: start at the dot on the left, follow any route to the end, and the characters you pass through form a string the regex accepts. Branches mean alternatives, a track that loops back underneath means repetition, and a track that bypasses a box above means that part is optional. Coloured frames are capture groups (the same colours are used in your highlighted matches), dashed frames are lookarounds that check without consuming text, and pill-shaped boxes are anchors that match a position rather than a character. Click a match in the results and each group frame shows the exact value it captured, or 'no match' if that group was skipped.
In the diagram
Regex syntax
Meaning
Box with quoted text
abc \. \n
These exact characters
Box listing 'one of:'
[a-z0-9_]
Any single character from the set
Box listing 'none of:'
[^\s@]
Any single character NOT in the set
Green box (digit, word character…)
\d \w \s .
A character class shorthand
Pill-shaped box
^ $ \b
An anchor: a position, not a character
Track splits into branches
cat|dog
Either alternative
Track loops back underneath
+ * {2,5}
Repeat (label shows how many times)
Track bypasses above
? * {0,3}
The part is optional
Dashed loop
+? *?
Lazy: repeat as few times as possible
Coloured frame '#1 name'
(…) (?<name>…)
Capture group, numbered left to right
Dashed frame 'followed by:'
(?=…) (?!…) (?<=…)
Lookahead / lookbehind
Regex cheat sheet: the syntax you'll use every day
Open the built-in cheatsheet above the tester and click any token to insert it at your cursor. These are the building blocks of nearly every pattern:
Token
Matches
Example
\d
A digit 0-9
\d{4} matches 2026
\w
Letter, digit or underscore
\w+ matches user_42
\s
Whitespace (space, tab, newline)
a\sb matches 'a b'
.
Any character except a line break
a.c matches abc, a-c
[abc] / [^abc]
One of / none of the listed characters
[aeiou] matches a vowel
^ and $
Start and end of the string (or line with m)
^\d+$ is digits only
\b
A word boundary
\bcat\b skips 'concatenate'
* + ?
0+, 1+, or 0-1 repetitions
colou?r matches color, colour
{n,m}
Between n and m repetitions
\d{2,4}
(…) and (?<name>…)
Capture group / named group
(?<year>\d{4})
(?:…)
Group without capturing
(?:ab)+
\1, \k<name>
Same text as an earlier group
(\w)\1 matches 'll'
(?=…) (?!…)
Followed by / not followed by
\d+(?=px)
(?<=…) (?<!…)
Preceded by / not preceded by
(?<=\$)\d+
Regex flags explained
Flags change how the whole pattern behaves. Toggle them with one click; hover a flag to see what it does.
Flag
Name
Effect
g
global
Find every match instead of stopping at the first
i
ignore case
Letters match in upper or lower case
m
multiline
^ and $ match at the start/end of every line
s
dotAll
. also matches line breaks
u
unicode
Treats emoji and astral characters as one character; enables \p{…}
v
unicode sets
Everything u does, plus set operations like [\p{L}--[a-z]]
y
sticky
Each match must start exactly where the previous one ended
Replace, extract, split and unit-test in one place
Switch to Replace to build a find-and-replace rule with $1, $<name>, $& and $$ tokens; the result highlights every inserted piece so you can check it before running it on real data. Extract turns every match into a list using a template (for example $2, $1 to swap two groups), with unique and sort options and CSV or JSON export for spreadsheets. Split shows exactly what String.split() returns, including captured separators. Unit tests let you pin down behaviour: add strings that must match, must match completely, or must not match, and the pass/fail count updates on every keystroke, so a small change to your pattern never quietly breaks a case you already fixed.
Catastrophic backtracking (ReDoS) and how this tester protects you
Some patterns, such as (a+)+$ or (\w+\s?)*$, can be split between their repetitions in exponentially many ways. When the input almost matches, the engine tries every combination and can freeze a browser tab or take a server down, a vulnerability known as ReDoS (regular expression denial of service). This tester runs every pattern in a separate Web Worker with a two-second limit: if the engine is stuck it is stopped and you get a clear warning instead of a frozen page. A built-in linter also flags the risky shape (a repeated group whose inner part repeats too) before you ship it, along with other common mistakes like an unescaped dot in a domain name, [A-z] ranges and empty alternatives.
Use the same regex in Python, PHP, Java, C#, Go, Rust and Ruby
The tester runs your browser's own JavaScript (ECMAScript) regex engine, so results are exact for JavaScript, TypeScript and Node.js. The Code tab turns your pattern into ready-to-paste code for eight other languages and converts the parts that differ: named groups become (?P<name>…) for Python, flags become RegexOptions for C# or inline (?i) for Go and Rust, and replacement tokens are rewritten for each language. A compatibility table lists every feature your pattern uses and whether each engine supports it:
Start from a tested pattern or generate one from examples
The pattern library holds 40 ready-made, tested expressions, each with sample text: email, URL, IPv4 and IPv6, E.164 and US phone numbers, strong passwords, UUIDs, semantic versions, UK postcodes, ISO and DD/MM/YYYY dates, prices, hashtags, @mentions, Markdown links, HTML tags, Apache/Nginx log lines, duplicate words and more. If you'd rather start from your data, paste a few examples into Build: the generator groups letters, digits and symbols into a pattern such as ^\d{4}-\d{2}-\d{2}$ that you can refine. Build can also escape any literal text so characters like . * ? ( ) $ are matched exactly.
Private by design
Everything runs locally in your browser's JavaScript engine: nothing you type is uploaded, logged or stored on a server. Your last session is kept in this browser so you can pick up where you left off, saved patterns stay on your device, and share links carry the pattern, text and tests inside the URL itself, so nothing is stored on our side.
Frequently asked questions
What regex flavour does this tester use?
It uses your browser's own JavaScript (ECMAScript) regular expression engine, the same one Chrome, Firefox, Safari and Node.js use, including the flags g, i, m, s, u, v and y. Results are exact for JavaScript and TypeScript; the Code tab converts the pattern for other languages.
Can I test capture groups?
Yes. Every match lists its position and the value of each numbered and named group, groups are colour-highlighted inside your text, and clicking a match shows each group's captured value right on the diagram.
How does the replace preview work?
Type a replacement using $1, $2 for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. The result updates live and highlights every inserted piece, exactly as String.replace() would produce it.
Is my test data private?
Yes. The regex runs entirely in your browser, in a local Web Worker. Your patterns and test strings are never uploaded; saved patterns stay in this browser only.
How do I test a regular expression against my text?
Type your pattern and paste sample text; matches are highlighted live, with capture groups shown, so you can see exactly what your regex matches and refine it instantly.
Why does my regex not match anything?
Common causes are a missing flag (i for case, m so ^ and $ work per line, s so . crosses line breaks), an unescaped special character, or syntax from another language. Hover the diagram to see what each part expects, read the plain-English explanation, and check the warnings under the pattern.
Can I test the same pattern for JavaScript and other flavors?
The matching runs on the JavaScript engine, and the Code tab generates working code for Python, PHP, Java, C#, Go, Rust and Ruby, converting named groups, flags and replacement syntax. A compatibility table shows which features, such as lookbehind or back-references, are not supported in each engine.
What is a regex visualizer or railroad diagram?
A regex visualizer draws a regular expression as a railroad diagram: a track you follow from left to right where branches are alternatives, loops are repetitions and bypasses are optional parts. It makes long patterns far easier to read than the raw syntax. Here the diagram is interactive: hover a box to highlight it in the pattern and see a plain-English explanation.
Can I download the regex diagram?
Yes. Use the SVG or PNG buttons above the diagram to download it for documentation, code reviews or teaching material. Zoom and fit-to-width controls help with long patterns.
What is catastrophic backtracking (ReDoS)?
It happens when a pattern like (a+)+$ can split the same text between nested repetitions in exponentially many ways, so a near-miss input makes the engine run for seconds or hours. This tester runs patterns in a Web Worker, stops them after two seconds, and warns about nested quantifiers before you deploy them.
How do I convert a JavaScript regex to Python?
Open the Code tab and choose Python. The tool rewrites (?<name>…) as (?P<name>…), \k<name> as (?P=name), maps the i, m and s flags to re.IGNORECASE, re.MULTILINE and re.DOTALL, and converts $1 replacements to \g<1>. Note that Python's built-in re module doesn't support \p{…} Unicode properties.
What do the regex flags g, i, m, s, u, v and y mean?
g finds all matches, i ignores case, m makes ^ and $ work on every line, s lets . match line breaks, u enables full Unicode and \p{…} properties, v adds Unicode set operations, and y (sticky) only matches at the exact position where the last match ended.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, {n,m}) match as much as possible, then give characters back if needed; lazy ones (*?, +?, {n,m}?) match as little as possible and expand only when needed. For example <.+> matches a whole line of tags, while <.+?> matches one tag at a time. In the diagram, a lazy loop is drawn dashed.
How do lookahead and lookbehind work?
They check what comes after (?=…) or before (?<=…) the current position without including it in the match; the negative forms (?!…) and (?<!…) require that the text is NOT there. For example \d+(?=px) matches 12 in '12px'. JavaScript supports lookbehind of any length.
Can this tool generate a regex for me?
Yes. Paste a few examples into the Build tab and it suggests a pattern by generalising letters, digits and symbols (for example 2026-09-24 becomes \d{4}-\d{2}-\d{2}). You can also start from 40 tested patterns in the library, such as email, URL, IP address, phone number, date and password rules.
How do I write unit tests for a regular expression?
Open the Unit tests tab and add strings that should match, should match completely, or should not match. Every test is re-run on each keystroke with a pass/fail count, and Import lines turns each line of your test text into a test case.
Can I share a regex with someone?
Click Share link to copy a URL that reopens the exact pattern, flags, test text, replacement and unit tests. Everything is encoded inside the link itself, so nothing is stored on a server.
How is this different from regex101 or RegExr?
regex101 lets you switch between several engines such as PCRE, Python and Java, which this tool doesn't. This tester focuses on the JavaScript engine your code actually runs on and adds an interactive railroad diagram, unit tests, ReDoS protection, code export for 9 languages and a compatibility table, with no account and nothing uploaded.