Matches appear here as you type.
About this tool
A free online regex tester, explainer and builder for developers. Type a regular expression and every match lights up in your test text as you type, with capture groups colored and listed. The pattern itself is syntax-highlighted, errors are underlined at the exact character with a plain-English fix, and the Explain tab decomposes any regex into a token-by-token breakdown and a one-sentence summary, while the Diagram tab draws it as a railroad diagram. A built-in checker warns about catastrophic backtracking (ReDoS) and common mistakes before they reach production. Replace, extract or split text with a highlighted preview of every change, write unit tests that run on every edit, build a pattern visually, generate one from examples or generate random strings that match it, check which engines support it, start from 40+ ready-made patterns or your own saved ones, and copy working code for JavaScript, Python, Java, Kotlin, C#, Go, PHP, Ruby, Rust and Swift. Patterns run in your browser's JavaScript engine inside a sandboxed worker, so a runaway regex can't freeze the page, and nothing is uploaded.
Features
Live match highlighting
Every match is highlighted in the test text as you type, with alternating colors so neighbors stay distinct. Empty matches show as a thin marker. Select a match to color its capture groups inside it.
Syntax-highlighted pattern editor
Anchors, quantifiers, groups, classes, escapes and backreferences each get their own color. Matching brackets light up at the cursor, nesting depth is color-coded, and errors are underlined at the exact character.
Regex explainer
The Explain tab decomposes the pattern into a nested tree, one row per token or group, each in plain English, plus a one-sentence summary. Hover a row to highlight that part of the pattern.
Railroad diagram visualizer
See the pattern as a railroad diagram: boxes for each character, class and anchor, branches for alternatives, arcs for optional and repeated parts, and labeled frames for groups and lookarounds. Download it as SVG or PNG for docs and code reviews.
ReDoS and performance checker
Static analysis flags nested quantifiers like (a+)+, overlapping alternatives inside loops and adjacent loops that can match the same text, the patterns behind catastrophic backtracking, each with a suggested fix.
Regex linter
Catches common mistakes: [A-z] matching punctuation, | inside a character class, {,5} that JavaScript treats as text, duplicate characters in a class and ^…$ without the m flag on multi-line input.
Helpful error messages
Instead of a bare "Invalid regular expression", you get the position and the fix: an unclosed group, a range out of order, a quantifier with nothing to repeat, an unknown group name or Python-only syntax.
Capture groups in detail
Numbered and named groups are listed for every match with their values and positions. A group table shows each group's pattern and the $1 or $<name> reference to use in a replacement.
Replace, extract and split
Preview String.replace output with $1, $<name> and $& references, extract every match through a template (with unique-only and custom separators), or split the text at each match.
Regex unit tests
Add cases that should match, match fully or not match. They run on every keystroke and the tab shows a pass count, so an edit that breaks an edge case is caught immediately. Turn each line of the test string into a test in one click.
Visual regex builder
Create a regex without remembering syntax: add blocks such as digit, letter, exact text or either-of, set how many times each repeats, capture them by name and see the pattern and its explanation update.
Generate regex from examples
Paste values that should match, and optionally some that shouldn't. The generator finds what they share and suggests patterns from specific to loose, showing which candidates accept and reject your examples.
Generate matching strings
Produce random strings that your pattern fully matches, checked against the real engine, in short, medium or long variants. Add them as unit tests or append them to the test string in one click.
Engine compatibility matrix
See which features your pattern uses (lookbehind, named groups, backreferences, Unicode properties and more) and whether JavaScript, PCRE, Python, Java, .NET, Go, Rust and Ruby support each one.
Code for 11 languages
Copy ready-to-run code for JavaScript, TypeScript, Python, Java, Kotlin, C#, Go, PHP, Ruby, Rust and Swift. Strings are escaped correctly, flags and named groups are converted, and unsupported features are flagged.
Pattern library and cheat sheet
Load 40+ tested patterns with sample text, from email, URL, IPv4 and ISO dates to semantic versions, JWTs, PAN, GSTIN and IFSC codes. The cheat sheet inserts any token at the cursor.
Saved patterns and focus mode
Name and save patterns with their test text in this browser, then reload them from the Library tab. Focus mode fills the window with the editor for long logs and complex patterns.
Safe, private and shareable
Matching runs in a Web Worker with a time limit, so catastrophic backtracking stops instead of hanging the tab. Your work is autosaved in this browser, and share links keep the pattern and text in the URL fragment, never on a server.
How to test a regular expression online
Start with the pattern field at the top. As you type, the status line shows how many matches the pattern finds and how long it took, or exactly what is wrong if the pattern is invalid. Move the cursor through the pattern and the same line describes the token under it, so \d{4} reads as "exactly 4 digits" without leaving the editor.
Flags change how the whole pattern behaves. Turn on g to find every match instead of the first, i to ignore letter case, and m so that ^ and $ match at each line rather than only at the start and end of the text. The s flag lets . match line breaks, u and v enable full Unicode support such as \p{L} for any letter, y makes matching sticky and d records group positions.
Put realistic data in the test string, including the values that should not match. Select any highlighted match, in the text or in the Matches tab, to see each capture group colored inside it. Export all matches as CSV or JSON when you need them elsewhere.
- Paste /pattern/flags straight from your code: the slashes and flags are split out for you.
- Use the Library tab to start from a tested pattern for emails, URLs, dates, IP addresses and more.
- If matching takes longer than two seconds it is stopped and you are warned about catastrophic backtracking.
Regex explainer: decompose any pattern into plain English
Regular expressions are compact but hard to read later. The Explain tab parses the pattern and decomposes it into a tree: each row pairs a piece of the pattern with what it matches. Groups and alternations nest their contents underneath, adjacent literal characters are merged into one row, and quantifiers are folded into the thing they repeat, so [a-z]+ reads as "one or more lowercase letters".
Above the tree, a one-sentence summary describes the whole pattern in order. Below it, a group table lists every capture group with its pattern and the reference to use in replacements. Hover any row to highlight that part of the pattern, or select it to put the cursor there.
^(?<year>\d{4})-(?<month>0[1-9]|1[0-2])$
Finds the first occurrence of the start of the text, then [exactly 4 digits (0–9)]
saved as "year", then "-", then ["0", then a digit from 1 to 9 or "1", then a digit
from 0 to 2] saved as "month", then the end of the text.Regex visualizer: read a pattern as a railroad diagram
The Diagram tab draws the pattern as a railroad diagram. Start at the dot on the left and follow any track to the dot on the right: every path you can take spells out a string the regex matches. Boxes are characters, character classes and anchors; a fork is an alternation; an arc above a box means it is optional, and an arc below means it repeats, labeled with the count. Groups and lookarounds are dashed frames named after their number or role.
Hover or select a box and the matching part of the pattern lights up in the editor. Fit scales the diagram to the panel and 100% shows it at full size. Download SVG for crisp diagrams in documentation, or PNG for chats and tickets.
Catch catastrophic backtracking (ReDoS) before it ships
Most regex engines, including JavaScript, Java, Python, PCRE and .NET, backtrack: when part of a match fails they go back and try other ways to split the text. Some patterns give the engine exponentially many ways to try, so a 30-character input can take seconds or hang a server. Attackers exploit this as regular expression denial of service (ReDoS).
The tester checks every pattern as you type and shows a Slow-regex risk badge when it finds a known culprit. The Explain tab lists each finding with the exact part of the pattern and a fix. Matching also runs in an isolated worker that is stopped after two seconds, so pasting an attack string can never freeze the page. Some browsers, including Chrome, fall back to a non-backtracking engine for certain patterns and finish quickly anyway; the warning still matters, because Java, Python, PHP and .NET servers have no such fallback.
- Nested quantifiers: (a+)+, (\w+\s?)*, (.*)*
- Overlapping alternatives inside a loop: (\w|\d)+, (a|ab)*
- Adjacent loops over the same characters: \d+\d+, .*.*=, \s*\s+
Vulnerable: ^([a-zA-Z0-9]+\.?)+@example\.com$
Safe: ^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@example\.com$Create a regex without memorizing syntax
The Build tab offers three ways to create a pattern. The visual builder lets you stack blocks, such as start of line, exact text, digit, letter, one of these characters or either of these words, and set how often each repeats: once, optional, one or more, exactly N or between N and M. Any block can be captured, with or without a name, and the generated pattern and its explanation update as you go.
Sample strings does the reverse of testing: it generates random strings your pattern accepts, each verified by the real engine. Reading them is a quick way to notice that a pattern allows more than intended, and Add as tests turns them into unit tests.
From examples works the other way round: paste a few values the regex should match and it infers the structure. INV-2024-0012 and INV-2025-3345 become ^INV-\d{4}-\d{4}$, keeping the shared text and generalizing the rest. Add values that must not match to see which suggestion is strict enough. Escape text turns any literal string into a safe pattern by escaping characters such as . $ ( and [.
Find and replace with regex, extract matches and split text
In the Replace tab, the result updates as you type a replacement. Use $1, $2 and so on for numbered groups, $<name> for named groups, $& for the whole match, and $$ for a literal dollar sign. Without the g flag, only the first match is replaced, exactly as in JavaScript's String.replace.
Extract builds a list from the matches instead, with each one formatted by a template: $<domain> lists only the domain part of each email, and Unique only removes repeats. Split cuts the text at every match and shows the pieces, which is handy for messy delimiters such as commas with optional spaces.
Pattern: ^(\w+),\s*(\w+)$ flags: gm
Replacement: $2 $1
Lovelace, Ada → Ada Lovelace
Turing,Alan → Alan TuringUsing your regex in Java, Python, JavaScript and other languages
Regex engines differ in small but important ways. The Code tab writes a working snippet for 11 languages and converts what it can: Java and C# strings get their backslashes doubled or a verbatim string, Python uses a raw string and its (?P<name>…) group syntax, Go and Rust receive inline (?i) style flags, PHP gets delimiters and modifiers, and replacement references are rewritten to each language's form.
Where a feature can't be converted, a note says so. Go's RE2 engine and Rust's regex crate don't support lookaround or backreferences, Java group names can't contain underscores, Python's \d matches Unicode digits unless you add re.ASCII, and in Ruby ^ and $ always match at line breaks.
How to use it
- Type or paste a pattern into the regex field. Pasting a literal such as /\d+/g splits the pattern and flags automatically. Toggle flags such as g (global), i (ignore case) and m (multiline) with the chips below it.
- Paste the text to search into Test string. Matches highlight as you type; select a match in the text or in the Matches tab to see its capture groups, and move the cursor through the pattern to see what each token does.
- Use the tabs to explain the pattern in plain English, replace or extract text, add test cases, build a pattern from blocks or examples, or copy code for your language. Share copies a link that keeps everything in the URL.
Common uses
- Debug a validation pattern for emails, phone numbers, dates or IDs before shipping it in Java, JavaScript or Python
- Understand a regex you inherited by reading its token-by-token explanation instead of decoding it by hand
- Clean up or reformat text in bulk: swap name order, pull every URL out of a log, trim whitespace or split CSV-like data
Common questions
Which regex flavor does this tester use?
It uses your browser's JavaScript (ECMAScript) regex engine, including modern features such as named groups, lookbehind, Unicode property escapes with the u flag, set operations with the v flag and inline modifiers where your browser supports them. The Code tab converts patterns for Java, Python, PCRE (PHP), .NET, Go, Ruby, Rust and Swift and warns about features those engines lack.
Is my data sent to a server?
No. The pattern and test text are processed in your browser, in a Web Worker on your device. They are autosaved only in this browser's local storage. Share links store everything in the part of the URL after #, which browsers never send to the server.
What does the Explain tab do?
It decomposes the regex into its parts and describes each one in plain English: anchors, characters and character classes, quantifiers, groups, lookarounds, alternations and backreferences, nested the way the engine reads them. It also writes a one-sentence summary of the whole pattern.
Why is my regex timing out?
Matching stops after two seconds to protect the page. This usually means catastrophic backtracking: nested or overlapping quantifiers such as (a+)+, (.*)* or (\w|\d)+ followed by something that fails, which makes the engine try exponentially many combinations. Make the repeated part more specific, or remove the nesting.
How do I match a whole line or the whole value?
Wrap the pattern in ^ and $. Without the m flag they match the start and end of the entire text; with m they match the start and end of each line, which is what you want when the test string contains one value per line.
How do I match a literal dot, bracket or other special character?
Put a backslash before it: \. matches a dot, \( a parenthesis and \$ a dollar sign. The characters that need escaping are . * + ? ^ $ { } ( ) [ ] | \ and /. Build → Escape text escapes a whole string for you.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers such as * and + match as much as possible and then give characters back if needed; lazy ones such as *? and +? match as little as possible. On <b>bold</b>, <.+> matches the whole string while <.+?> matches just <b>.
Can it generate a regex for me?
Yes. Build → From examples suggests patterns from values you paste and checks them against values that must not match, and the visual builder creates a pattern from blocks. The Library tab has 40+ tested patterns for common formats.
How do I visualize a regular expression?
Open the Diagram tab. It draws the pattern as a railroad diagram, with alternatives as branches, optional parts as arcs above and repetition as loops below. Select any box to find that part in the pattern, and download the diagram as SVG or PNG.
How can I check a regex for ReDoS?
Type it in: the tester analyzes every pattern for nested quantifiers, overlapping alternatives inside loops and adjacent overlapping loops, and shows a Slow-regex risk badge with the details in the Explain tab. Matching stops after two seconds, so testing a long, almost-matching input never freezes the page.
Will my regex work in Python, Java or Go?
The Code tab includes an engine compatibility matrix that lists each feature your pattern uses and whether JavaScript, PCRE (PHP), Python, Java, .NET, Go, Rust and Ruby support it. For example, Go and Rust have no lookaround or backreferences, and Python needs fixed-length lookbehind.
Can I generate test data from a regex?
Yes. Build → Sample strings creates random strings that fully match your pattern, verified by the browser's regex engine. Choose how many and how long, then copy them, add them as tests or append them to the test string.
Does the email regex validate every valid address?
No regular expression can fully validate email addresses. The library pattern is a practical check for the [email protected] shape, which catches typos. To be sure an address works, send a confirmation email.
Can’t find the tool you need?
Tell us what you’d like it to do. We’ll review your suggestion for a future tool.