Regex tester
Enter a pattern and some text to test it on, and every match is highlighted as you type.
Examples
Use $1 or $<name> for groups, $& for the whole match and $$ for a dollar sign.
Common tokens
- .
- any character except a line break
- \d
- a digit 0–9
- \w
- a letter a–z, digit or underscore
- \s
- space, tab or line break
- \D \W \S
- the opposite of \d, \w and \s
- \b
- boundary between a word and a non-word character
- ^
- start of the text, or of the line with m
- $
- end of the text, or of the line with m
- [abc] [a-z]
- one of the characters, or a character in the range
- [^abc]
- none of the characters
- a|b
- a or b
- (…)
- capturing group
- (?:…)
- non-capturing group
- (?<name>…)
- named group
- \1 \k<name>
- the same text as group 1 or the group called name
- *
- zero or more times
- +
- one or more times
- ?
- zero or one time
- {3} {2,5} {2,}
- exactly 3, 2 to 5, or at least 2 times
- *? +? ??
- as few times as possible
- (?=…)
- followed by
- (?!…)
- not followed by
- (?<=…) (?<!…)
- preceded by, not preceded by
- \p{L}
- a letter in any script (needs u or v)
How it works
A regular expression is a pattern that describes text. \d+ means one or more digits, [a-z] a letter from a to z and ^ the start of the text. The pattern is tried against the text from left to right, and every place where it fits is a match.
The tester uses your browser’s own engine, which is the flavour of regular expressions defined in the ECMAScript standard for JavaScript. It differs from PCRE, Python and .NET in a few ways: there are no possessive quantifiers or atomic groups, for example, and lookbehind may be of any length.
Flags change how the pattern is read. g finds every match rather than just the first, i ignores the difference between upper and lower case, m makes ^ and $ apply to each line and s lets the dot match line breaks. u reads the text as Unicode characters rather than UTF-16 units, and v is a stricter version of u from ECMAScript 2024 with set operations in character classes. y requires each match to start exactly where the previous one ended, and d records the positions of groups.
Parentheses capture what they matched and are numbered by their opening parenthesis, from the left. (?<name>…) gives a group a name, and (?:…) groups without capturing. In the replacement, $1 stands for group 1, $<name> for a named group, $& for the whole match and $$ for a dollar sign. Without the g flag only the first match is replaced.
Some patterns take an extremely long time, such as (a+)+$ against a long run of a followed by a different character. The engine then tries combinations whose number grows exponentially with the length of the text, known as catastrophic backtracking. Here the search runs in a separate thread that is stopped after two seconds, so the page does not freeze. In a program on a server the same pattern can become a security risk (ReDoS).
Positions are counted in UTF-16 units, as in JavaScript, so an emoji counts as two. An empty match, such as ^ or \b, is marked with a thin line. Your text never leaves your browser.