How to test a regular expression
- Type your pattern in the box at the top, and switch flags on or off. Use g to find every match.
- Paste the text to search. Matches are highlighted as you type, and each one is listed with its capture groups.
- Type a replacement such as
$1-$2or$<name>to preview the result, and read the step by step explanation to check what each part does.
The patterns run as JavaScript regular expressions. If you plan to use the pattern in Python, Go, or another language, check the details that differ, such as lookbehind support and flags written inside the pattern.
Regex cheat sheet
Characters
.- Any character except a line break
\d \w \s- Digit, word character, whitespace
\D \W \S- The opposite of each
[abc] [a-z] [^abc]- One of, a range, none of
\. \* \(- A special character, as plain text
Position
^ $- Start and end of the text (or line with m)
\b \B- Word boundary, not a word boundary
(?=x) (?!x)- Followed by x, not followed by x
(?<=x) (?<!x)- Preceded by x, not preceded by x
Repeats
* + ?- Zero or more, one or more, zero or one
{3} {2,} {2,5}- Exactly 3, at least 2, between 2 and 5
*? +? ??- Lazy: as few as possible
Groups
(abc)- Capture group, numbered from 1
(?<name>abc)- Named capture group
(?:abc)- Group without capturing
a|b- a or b
\1 \k<name>- Repeat what a group matched
Replacement
$1 $2- Text of a numbered group
$<name>- Text of a named group
$& $$- The whole match, a literal $
Questions
Is my text uploaded anywhere?
No. The pattern and the test text are matched by your browser's own regular expression engine, so logs, emails, and other private text never leave your device.
Which regex flavor does this use?
JavaScript (ECMAScript), the engine built into your browser. It supports named groups, lookbehind, and Unicode property escapes. Features from other flavors, such as possessive quantifiers and inline flags like (?i), are not available.
Why was my pattern stopped?
Some patterns, such as (a+)+$ on a long run of "a" letters, take exponentially longer as the text grows. This is called catastrophic backtracking. Matching runs in a background thread with a two second limit, so the page never freezes. Rewrite the pattern so each part can match only one way.
How do I use a capture group in the replacement?
Write $1, $2, and so on for numbered groups, or $<name> for a named group. $& inserts the whole match, and $$ inserts a literal dollar sign. The preview updates as you type.
Why do I only see one match?
Without the g (global) flag, a regular expression stops after the first match. Turn on g to find all of them.
Credits
Built by OneTooling using standard browser features. No third-party code runs on your data.