Regex Tester: Test Regular Expressions Online With Live Matches
This free regex tester lets you write a regular expression and see what it matches as you type. Paste your sample text, add the flags you need, and the matches are highlighted at once, with capture groups, positions and a replace preview listed below. It also explains each part of your pattern in plain English, and it runs in your browser.
Type a pattern into the box above and paste some test text. Matches appear as you type.
Use the toolExplanations cover standard JavaScript syntax. Anything unusual is shown as a plain character.
Live matches
Highlighted as you type, with positions and capture groups.
Replace and Explain
Test $1 and $
Stops slow patterns
A time limit means catastrophic backtracking cannot freeze the page.
Private by design
Your pattern and text never leave your browser.
Type a pattern and paste test text. Every match is highlighted live, with its position and capture groups. Use Replace to test $1 and $, and Explain for a plain-English breakdown.
Key Takeaways
- Type a pattern and test text, and every match is highlighted live, with its position and capture groups.
- Flags change the behavior: g finds all matches, i ignores case, m makes ^ and $ work per line, and s lets the dot match newlines.
- The Replace tab shows the result of a find and replace using $1 or $<name> for groups, before you use it anywhere.
- This tester uses the JavaScript regular expression engine. Other languages differ in small but important ways.
- Test with text that should not match as well as text that should, and avoid patterns that nest quantifiers.
Test Regular Expressions Online in Real Time
A good regex tester earns its keep quickly, because regular expressions are compact and unforgiving. One misplaced character changes what a pattern matches, and the mistake is hard to see by reading. Testing a pattern against real sample text is the quickest way to find out what it does.
Everything runs in your browser. The pattern and the text you paste are not uploaded, so it is safe to test against logs, config files and data that you would not post online.
How to Use the Regex Tester
-
1STEP 1 Type your regular expression in the pattern box, without the surrounding slashes.
-
2STEP 2 Paste or type the text you want to test in the large box. Add some lines that should match and some that should not.
-
3STEP 3 Switch the flags on or off. Use g to find every match and i to ignore case.
-
4STEP 4 Read the results. Matches are highlighted in the text, and the Matches and Groups tabs list each one with its index and capture groups.
-
5STEP 5 Open Replace to try a substitution, or Explain to see what each token in your pattern does. Copy the pattern when it works.
Regex Tester Flags Explained
Flags go after the pattern and change how it is applied. They can be combined in any order. The tester shows them as toggle buttons.
| Flag | Name | What it does |
|---|---|---|
g | Global | Finds all matches, not just the first one. |
i | Ignore case | Treats upper and lower case letters as the same. |
m | Multiline | Makes ^ and $ match at the start and end of each line. |
s | Dot all | Lets the dot (.) match newline characters too. |
u | Unicode | Treats the pattern as Unicode code points and enables \p{...} property escapes. |
v | Unicode sets | An upgrade of u with more Unicode features. |
y | Sticky | Matches only at the current position in the text. |
d | Indices | Returns the start and end positions of each group. |
Regex Cheat Sheet for the Regex Tester
This is a quick reference for the syntax the tester supports. The same table is available in the side panel while you work. For the complete syntax, see the MDN guide to regular expressions.
| Syntax | Meaning | Example |
|---|---|---|
. | Any character except a newline | a.c matches abc, a1c |
\d \w \s | Digit, word character, whitespace | \d{3} matches 123 |
\D \W \S | The opposite of each of the above | \S+ matches a run of non-space characters |
[abc] [^abc] | One of these characters, or none of them | [aeiou] matches a vowel |
* + ? | 0 or more, 1 or more, 0 or 1 | ab*c matches ac, abc, abbbc |
{n} {n,} {n,m} | Exactly n, at least n, between n and m | \d{2,4} matches 2 to 4 digits |
^ $ | Start and end of the text, or of each line with m | ^\d{3}$ matches exactly three digits |
\b \B | Word boundary, not a word boundary | \bcat\b matches cat, not concat |
(x) | Capturing group | (\d+)-(\d+) captures both numbers |
(?<name>x) | Named capturing group | (?<year>\d{4}) captures the year |
(?:x) | Non-capturing group | (?:ab)+ repeats ab without capturing |
x|y | Either x or y | cat|dog matches either word |
\1 \k<name> | Backreference to an earlier group | (\w)\1 matches a doubled letter |
x(?=y) x(?!y) | Followed by y, not followed by y | \d+(?=%) matches digits before a percent sign |
(?<=y)x (?<!y)x | Preceded by y, not preceded by y | (?<=\$)\d+ matches digits after a dollar sign |
Capture Groups, Named Groups and Backreferences
Parentheses do two jobs. They group part of a pattern so a quantifier can apply to all of it, and they capture the matched text so you can reuse it. The Groups tab lists each group for every match, numbered from 1 in the order the opening brackets appear.
Named Groups
Naming a group makes a pattern easier to read and to use. Write (?<year>\d{4})-(?<month>\d{2}) and the Groups tab shows year and month as labels. In a replacement, you can then refer to them as $<year> and $<month>.
Non-Capturing Groups
If you need grouping but not the captured text, use (?:...). It keeps the group numbers tidy and can be slightly faster.
Lookahead and Lookbehind
Lookarounds check what comes before or after a position without including it in the match. The pattern \d+(?=%) matches the digits in 50% but not the percent sign. They are useful when you want to extract a value and ignore its surroundings.
Regex Replace: Test Find and Replace Safely
Open the Replace tab and enter a replacement string. The tester shows the result for your sample text before you run it anywhere that matters. Use $1, $2 and so on for numbered groups, $<name> for named groups, and $& for the whole match.
| Pattern | Replace with | Input | Result |
|---|---|---|---|
(\w+)@(\w+)\.com | $2: $1 | ana@mail.com | mail: ana |
(?<d>\d{2})/(?<m>\d{2})/(?<y>\d{4}) | $<y>-$<m>-$<d> | 25/12/2026 | 2026-12-25 |
\s{2,} | One space | a b c (extra spaces) | a b c |
To check what a replacement changed in a long text, copy the before and after into the text compare tool and look at the differences.
Common Regex Patterns to Start From
These patterns are starting points. Real data is messier than examples, so always test them on your own sample text, including cases that should fail. You can load each one, with sample text, from the Common patterns list in the tester.
| Use | Pattern | Notes |
|---|---|---|
| Email address (simple) | [\w.+-]+@[\w-]+(?:\.[\w-]+)+ | Catches most addresses. It does not check every rule in the email standards. |
| URL | https?:\/\/[^\s/$.?#].[^\s]* | Matches http and https links up to the next space, so a full stop at the end of a sentence is included. |
| IPv4 address | \b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b | Limits each part to 0 to 255. |
| Date (YYYY-MM-DD) | \b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b | Checks the month and day range, but not whether the date exists. |
| Hex color | #(?:[0-9a-fA-F]{3}){1,2}\b | Matches #fff and #ffffff. |
| Whitespace at line ends | [ \t]+$ | Use with the m flag to find trailing spaces. |
| Duplicate word | \b(\w+)\s+\1\b | Finds repeated words, such as "the the". Use with the i flag. |
For a pure email check in a form, a basic pattern plus a confirmation email is more reliable than a very long pattern.
Regex Explainer: Understand What a Pattern Does
Not every regex tester explains the pattern, so this one adds a plain-English breakdown.
The Explain tab breaks your pattern into tokens and describes each one in plain English. For example, \b(\w+)\s+\1\b is described as a word boundary, a group of one or more word characters, one or more whitespace characters, a repeat of that first group, and a word boundary. It is a fast way to read a pattern you found online or wrote months ago.
Why Is My Regex Not Matching? Common Mistakes
- Forgetting the g flag. Without it, only the first match is found.
- Not escaping special characters. Characters such as
. * + ? ( ) [ ] { } ^ $ | \have special meaning, so use a backslash to match them literally. - Greedy matching. Quantifiers match as much as they can. Add ? after one, as in
.*?, to make it match as little as possible. - Anchors without the m flag.
^and$match only the start and end of the whole text unless m is on. - The dot and newlines. The dot does not match a newline unless the s flag is on.
- Differences between languages. A pattern that works in JavaScript may need changes in Python, Java or PCRE.
- Validating too much. A strict pattern for names, phone numbers or emails will reject real values. Match what you need, not what you imagine.
Regex Performance and Catastrophic Backtracking
Some patterns can take a very long time on certain text. This happens when nested or overlapping quantifiers, such as (a+)+, give the engine an enormous number of ways to try a match that will fail. The effect is known as catastrophic backtracking, and it can freeze a page or a server.
- Avoid nesting quantifiers on the same characters.
- Anchor your pattern where you can, and make alternatives distinct.
- Test with long text that almost matches, because that is the worst case.
- Never run user-supplied patterns on a server without a time limit.
The tester stops a run that takes too long and tells you, so a slow pattern does not freeze your browser.
Regex Flavors: JavaScript, Python, Java and More
Regular expressions are similar across languages, but not identical. This tester uses the JavaScript engine in your browser, so what you see is how the pattern behaves in JavaScript and TypeScript.
| Language | Differences to watch for |
|---|---|
| Python | Named groups are written (?P<name>x). Use the re module and raw strings such as r"\d+". |
| Java | Backslashes must be doubled in strings, as in "\\d+". Matching uses the Pattern and Matcher classes. |
| PHP and PCRE | Patterns are written between delimiters, such as /\d+/i, and support more advanced features such as possessive quantifiers. |
| C# and .NET | Supports named groups and lookbehind, with some extra syntax such as balancing groups. |
Simple patterns move between languages unchanged. For complex ones, check the documentation for your language and test in that language as well.
Regex Generator: Build a Pattern From Examples
If you are not sure where to start, choose a pattern from the Common patterns list and adjust it. Add a few lines of sample text that should match and a few that should not, then edit the pattern until the highlights are what you expect. This works better than trying to write a long pattern in one go.
Privacy: Your Patterns and Text Stay in Your Browser
Matching runs on your device. The patterns and the text you test are not uploaded or stored, and they are gone when you close the tab. Share links hold the pattern, flags and text in the link itself, so check what you include before you send one.
FAQs
How do I test a regular expression online?
Type your pattern into the pattern box, paste your test text into the large box, and choose your flags. Matches are highlighted as you type, and the Matches and Groups tabs list each one with its position. Include text that should not match so you can see false positives.
Which regex flavor does this regex tester use?
It uses the JavaScript regular expression engine built into your browser, so results match how the pattern behaves in JavaScript and TypeScript. Most simple patterns work the same in Python, Java and PCRE, but features such as named group syntax differ, so test in your own language too.
What do the regex flags g, i, m and s mean?
The g flag finds all matches, not only the first. The i flag ignores upper and lower case. The m flag makes ^ and $ match at the start and end of each line. The s flag lets the dot match newline characters. You can combine flags in any order.
What is a capture group in regex?
A capture group is part of a pattern in parentheses, whose matched text is saved so you can reuse it. Groups are numbered from 1 by their opening bracket, and named groups use (?<name>x). The Groups tab shows what each group captured, and you can use them in a replacement as $1 or $<name>.
Why is my regex not matching?
Common causes are a missing g flag, unescaped special characters, anchors used without the m flag, a dot that needs the s flag, or a pattern written for another language. Read the error line, use the Explain tab to check each token, and test with a shorter sample text.
How do I use regex to find and replace text?
Open the Replace tab, enter your pattern and a replacement string, and check the result. Use $1 and $2 for numbered groups, $<name> for named groups and $& for the whole match. Test it on sample text first, so you know the change is right before you apply it.
What is catastrophic backtracking?
It happens when a pattern with nested or overlapping quantifiers, such as (a+)+, forces the engine to try a huge number of combinations on text that almost matches. The match can take seconds or minutes. Avoid nested quantifiers, anchor your patterns, and test on long near-matches.
Is my text or pattern saved or uploaded?
No. The matching runs in your browser, and the pattern and the text you enter are not sent to a server or stored. They disappear when you close the tab. A share link contains them inside the link itself, so check what you include before you send it.
Related Free Tools
Text Compare
Find every difference between two texts.
Open the toolJSON Formatter
Beautify, validate and minify JSON in your browser.
Open the toolHTML Encoder and Decoder
Encode and decode HTML entities.
Open the toolCase Converter
Switch text between nine case formats in one click.
Open the toolReady to test your pattern?
Scroll back to the tester, paste your text and see your pattern match in real time.
Use the tool