Free plan

50 submissions/month · no credit card · View plans

Regex Tester

/ /
Common patterns:
Matches

Replace

Runs entirely in your browser. Nothing you paste is uploaded or stored.

How to test a regular expression

  1. Type your pattern between the slashes. You do not need to escape the slashes themselves.
  2. Add flags in the small box or tick them below. Use g to find every match instead of only the first.
  3. Paste the text you want to search into Test string. Matches are highlighted as you type, and the table lists each match with its position and capture groups.
  4. Open Replace to preview a find-and-replace, using $1 or $<name> to reuse captured text.

Regex cheat sheet

PatternMeaning
.Any character except a line break (any character with the s flag)
\d \w \sDigit, word character (letter, digit, underscore), whitespace
\D \W \SAnything that is not a digit, word character or whitespace
[abc] [^abc] [a-z]One of a, b or c; anything except them; a range
^ $Start and end of the string (of each line with m)
\bWord boundary
* + ?0 or more, 1 or more, 0 or 1
{3} {2,} {2,5}Exactly 3, at least 2, between 2 and 5
*? +?Lazy versions: match as little as possible
(abc)Capture group, reused as $1
(?<name>abc)Named capture group, reused as $<name>
(?:abc)Group without capturing
a|ba or b
(?=x) (?!x)Followed by x; not followed by x (lookahead)
(?<=x) (?<!x)Preceded by x; not preceded by x (lookbehind)
\. \* \\A literal dot, star or backslash

Regex for form validation

Regular expressions are most often used to check what people type into forms. HTML can do this without JavaScript using the pattern attribute. The browser anchors the pattern to the whole value for you, so you leave out ^ and $:

<input name="zip" pattern="\d{5}(-\d{4})?" title="5 digit ZIP code" required>

Keep validation patterns forgiving. A strict email or phone regex rejects real customers with unusual but valid input, and every rejected form is a lost lead. Check the basic shape on the page, then do the real check on the server, or let a form backend like formvoxo receive the submission, filter spam and email it to you. For checking that an email address can actually receive mail, use the email validator.

Avoiding slow patterns

Nested quantifiers like (a+)+ or (\w*)* can make the regex engine try an exponential number of paths when a match fails. This is called catastrophic backtracking, and on a server it can be used to freeze your app (a ReDoS attack). This tester runs your pattern in a separate worker and stops it after one second, so you can find such patterns safely. Rewrite them so each character can be matched only one way, for example a+ instead of (a+)+.

Want the full guide? Read Regex Cheat Sheet for Form Validation: Email, Phone, ZIP and More.

Frequently asked questions

Which regex flavour does this use? +

JavaScript (ECMAScript), the same engine as your browser and Node.js. Most syntax is shared with PCRE, Python and Java, but a few features differ, for example possessive quantifiers and recursion are not supported.

What do the flags g, i, m, s, u and y mean? +

g finds all matches instead of the first, i ignores case, m makes ^ and $ match at line breaks, s lets the dot match newlines, u turns on full Unicode support, and y (sticky) only matches at the current position.

How do I reference a capture group in the replacement? +

Use $1, $2 and so on for numbered groups, $<name> for named groups, and $& for the whole match. For example, replacing (\w+)@(\w+) with $2 at $1 swaps the two parts.

Why does the tester stop on some patterns? +

Patterns with nested quantifiers, such as (a+)+, can take exponential time on some inputs (catastrophic backtracking). The tester runs each pattern in a background worker and stops it after a second so your browser never freezes.

Is my test text sent anywhere? +

No. Matching runs locally in your browser. Nothing you type is uploaded or stored.

Need a backend for your HTML forms?

Point any form at formvoxo and get submissions in your inbox, with spam filtering built in. Free plan, no server code.

Create free account →