Regex tester
Write a regular expression and see what it matches as you type, with groups and replace.
Matches
Cheat sheet
Regular expression basics
| Pattern | Matches |
|---|---|
. | Any character except a line break |
\d \w \s | A digit, a word character (letter, digit, _), whitespace |
\D \W \S | Anything except a digit, word character or whitespace |
[abc] [^abc] [a-z] | One of a, b, c; anything but those; a range |
* + ? | Zero or more, one or more, zero or one of the previous item |
{3} {2,5} | Exactly 3; between 2 and 5 |
*? +? | Lazy: as few as possible |
^ $ | Start and end of the text (or line, with the m flag) |
\b | A word boundary |
(…) (?:…) (?<name>…) | Capturing, non-capturing and named groups |
a|b | a or b |
(?=…) (?!…) (?<=…) | Lookahead, negative lookahead, lookbehind |
Useful patterns
- Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2} - Simple email check:
^[^\s@]+@[^\s@]+\.[^\s@]+$ - Hex color:
#(?:[\da-f]{3}){1,2}\bwith the i flag - Trailing whitespace on each line:
[ \t]+$with the m flag
More tools
More on the bench
- JSON formatter and validatorPretty-print, minify and validate JSON, with the exact line of any error.
- Base64 encoder and decoderEncode text to Base64 and back, including URL-safe Base64 and emoji.
- URL encoder and decoderPercent-encode and decode URLs and query values, and break a URL into parts.
- Text diffCompare two texts or code snippets line by line or word by word.
- CSV to JSON converterConvert CSV to JSON and JSON to CSV, with delimiter detection.
- UUID generatorGenerate random v4 or time-ordered v7 UUIDs, one or a hundred at a time.
- JWT decoderRead the header and claims of a JSON Web Token, with expiry dates in plain English.
- Hash generatorSHA-1, SHA-256, SHA-384 and SHA-512 hashes of any text.
- Unix timestamp converterEpoch seconds or milliseconds to a readable date and back, in any time zone.
- Lorem Ipsum generatorPlaceholder paragraphs, sentences or words, plain or as HTML.
Frequently asked questions
Which regex flavor does this use?
JavaScript’s, exactly as in Chrome, Firefox, Safari and Node.js, because it runs on your browser’s own engine. Most syntax is shared with PCRE (PHP), Python and Java, but some features differ, such as lookbehind support in older engines and possessive quantifiers.
What do the flags mean?
g finds every match instead of only the first. i ignores case. m makes ^ and $ match at the start and end of each line. s lets . match line breaks too. u enables full Unicode matching, including \p{L} for any letter.
How do I use capture groups in a replacement?
Refer to numbered groups as $1, $2 and so on, and to named groups as $<name>. $& inserts the whole match. Turn on Replace to try it: the example rewrites 2024-03-10 as 10/03/2024.
Why did my pattern stop with a timeout?
Some patterns, typically nested quantifiers like (a+)+ or (\w*)*, can take exponentially long on text that almost matches. This is called catastrophic backtracking. The tester stops after 1.5 seconds; rewrite the pattern so each character can only be matched in one way.
Is my text sent anywhere?
No. Matching runs in your browser, in a background thread, and nothing is uploaded.