Test a regular expression.
Write a pattern and see every match highlighted, with groups and a replace preview.
Loading…
Next step: Clean text →
Three steps.
Type a pattern, or pick one from the common patterns.
Turn flags on or off and paste your test text.
Check the highlighted matches and groups, and try a replacement.
Which regex flavour is this?
It uses your browser's JavaScript engine, the same one that runs your front-end code and Node.js. Most syntax is shared with PCRE, Python and Java, but some features differ, such as lookbehind support in older browsers and possessive quantifiers, which JavaScript does not have.
The flags
- g: find all matches, not just the first.
- i: ignore upper and lower case.
- m:
^and$match at each line. - s:
.also matches line breaks. - u: full Unicode, needed for emoji and
\p{L}. - y: sticky, match only at the current position.
Patterns that freeze the page
Nested repeats like (a+)+$ can take exponential time on some inputs, a problem known as catastrophic backtracking or ReDoS. Here the pattern runs in a separate worker and is stopped after 1.5 seconds, so the page never hangs and you learn the pattern is risky before it reaches production.
Format is not validity
The ready patterns for codice fiscale and IBAN check the shape only. A string can match and still be wrong: real validation also needs the check characters.
Questions.
Do I write the slashes around the pattern?
No. Type only what goes between the slashes and set the flags with the buttons. Copy regex gives you the /pattern/flags form.
How do I use a group in the replacement?
Write $1 for the first group, $<name> for a named group, and $& for the whole match.
Why did my pattern stop after 1.5 seconds?
It was taking too long, usually because of nested repeats. Make the repeated parts more specific, for example [^,]+ instead of .+.