Test regular expressions online with live match highlighting, capture groups, flags and replace. Free and private.
Flags
Try an example
Runs in your browser with the JavaScript regex engine. Nothing is sent to a server.
NinjaFunction's Regex Tester lets you write a regular expression and see the result straight away. Matches are highlighted in your text, every match is listed with its position and capture groups, and you can switch flags on and off, try a replacement, or start from a ready example such as an email, date or web address. The page also has a regex cheat sheet. Patterns run in your browser with the JavaScript engine, and a pattern that runs too long is stopped for you, so nothing is sent to a server and the page never freezes.
$1 to see the text after the change.(?<year>\d{4}) and the replacement $<year> to keep patterns readable.These are the building blocks you will use most. Combine them to describe almost any piece of text.
| Pattern | What it matches |
|---|---|
. | Any character except a line break |
\d | A digit (0 to 9) |
\D | Anything that is not a digit |
\w | A letter, digit or underscore |
\W | Anything that is not a letter, digit or underscore |
\s | A space, tab or line break |
\S | Anything that is not whitespace |
[abc] | One of the characters a, b or c |
[^abc] | Any character except a, b or c |
[a-z] | Any lowercase letter from a to z |
| Pattern | What it matches |
|---|---|
^ | The start of the text (or of each line with the m flag) |
$ | The end of the text (or of each line with the m flag) |
\b | The edge of a word |
\B | Not the edge of a word |
| Pattern | What it matches |
|---|---|
* | Zero or more times |
+ | One or more times |
? | Zero or one time (optional) |
{3} | Exactly 3 times |
{2,5} | Between 2 and 5 times |
{2,} | 2 or more times |
*? | As few times as possible (lazy) |
| Pattern | What it matches |
|---|---|
(abc) | A capture group. Its text is kept as Group 1, 2, 3 and so on |
(?:abc) | A group that does not capture |
(?<name>abc) | A group with a name you choose |
a|b | Either a or b |
\1 | The same text that Group 1 matched |
(?=abc) | Followed by abc (lookahead) |
(?!abc) | Not followed by abc |
(?<=abc) | Preceded by abc (lookbehind) |
(?<!abc) | Not preceded by abc |
| Flag | Name | Effect |
|---|---|---|
g | Global | Finds all matches instead of stopping at the first |
i | Ignore case | Treats upper and lower case letters as the same |
m | Multiline | Makes ^ and $ match at the start and end of every line |
s | Dot matches newline | Lets the dot match line breaks as well |
u | Unicode | Handles emoji and other special characters correctly |
| Finds | Pattern |
|---|---|
| Email address | [\w.+-]+@[\w-]+(?:\.[\w-]+)+ |
| Web address | https?:\/\/[^\s/$.?#][^\s]* |
| Date (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} |
| IPv4 address | \b(?:\d{1,3}\.){3}\d{1,3}\b |
| Hex colour | #(?:[0-9a-fA-F]{3}){1,2}\b |
| Whole number | ^-?\d+$ |
| Spaces at the start or end | ^\s+|\s+$ |
These patterns are good for finding text. They do not prove that an email address or website really exists, and no single pattern can check every valid email address. To make sure an address works, send a message to it.
This tester uses the JavaScript regex engine. The basics are the same in Python, PHP, Java and .NET, but some details are not:
(?P<name>...), while JavaScript uses (?<name>...).\A or \Z anchors, no possessive quantifiers such as a++, and no atomic groups.(?i) are not supported in JavaScript, so use the flag buttons instead.Working with data in other formats? Try the JSON Formatter, the Text Diff Tool or the Unix Timestamp Converter.
A regular expression, or regex, is a short pattern that describes a piece of text. You can use it to find, check or replace text, for example to pull every email address out of a document or check that a field contains only digits.
Without the Global (g) flag, JavaScript stops after the first match. Switch on the Global flag to find all matches in the text.
g finds all matches, i ignores upper and lower case, m makes ^ and $ work on every line, s lets the dot match line breaks, and u turns on full Unicode support, which helps with emoji and other special characters.
Some patterns, such as (a+)+$, can take an enormous amount of time on certain text. This is called catastrophic backtracking. To keep your browser working, the tool stops any pattern that runs longer than 2 seconds. Use a simpler pattern, or avoid repeating a group that already repeats.
Most basic patterns work everywhere, but this tool uses the JavaScript engine, and other languages differ in small ways. For example, Python writes named groups as (?P<name>...), and JavaScript does not support \A, \Z, possessive quantifiers or inline flags such as (?i). Always test in the language you will use.
Turn on the Dot matches newline (s) flag so the dot matches line breaks too. You can also use [\s\S], which matches any character, including line breaks, without any flag.
No. The pattern runs in your browser. Nothing you type is sent or stored.