Regex Tester for JavaScript
Type a regular expression and some text. Every match is highlighted as you type, with its position and capture groups.
Matches
Regex cheatsheet
Characters
.- Any character except a line break (any at all with the s flag)
\d \D- A digit 0-9 / not a digit
\w \W- A word character [A-Za-z0-9_] / not one
\s \S- Whitespace (space, tab, line break) / not whitespace
[abc]- One of a, b or c
[^abc]- Any character except a, b or c
[a-z0-9]- A character in a range
\. \* \\- A literal dot, star or backslash (escape special characters)
Anchors
^ $- Start / end of the text (of each line with the m flag)
\b \B- A word boundary / not a word boundary
Quantifiers
* + ?- 0 or more / 1 or more / 0 or 1
{3} {2,} {2,5}- Exactly 3 / 2 or more / between 2 and 5
*? +?- Lazy: as few as possible
Groups
(abc)- Capture group, used as $1 in a replacement
(?<name>abc)- Named group, used as $<name>
(?:abc)- Group without capturing
a|b- a or b
\1- Back-reference to group 1
(?=x) (?!x)- Followed by x / not followed by x (lookahead)
(?<=x) (?<!x)- Preceded by x / not preceded by x (lookbehind)
Common regex patterns
Press Try to load a pattern and sample text into the tester.
-
Email address
/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g -
Indian mobile number
/^[6-9]\d{9}$/gm -
URL (http/https)
/https?:\/\/[\w.-]+(?:\/[\w\/.%?=&#-]*)?/g -
Date YYYY-MM-DD
/\b(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b/g -
PIN code (India)
/^[1-9]\d{5}$/gm -
PAN card
/^[A-Z]{5}\d{4}[A-Z]$/gm -
Hex colour
/#(?:[0-9a-fA-F]{3}){1,2}\b/g -
IPv4 address
/\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g -
Strong password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$/gm -
Repeated word
/\b(\w+)\s+\1\b/gi -
HTML tag
/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi -
Trim spaces
/^\s+|\s+$/gm
How to use the regex tester
- Type your regular expression in the Regex box without the slashes, or paste a full literal like
/\d+/gand the flags are picked up for you. - Tick the flags you need: g finds every match, i ignores case, m makes
^and$work per line. - Type or paste your Test text. Matches are highlighted as you type, and the table lists each match with its position and capture groups.
- Turn on Replace to preview
text.replace()with$1or$<name>, then copy the ready-made JavaScript line.
Everything runs in your browser. Nothing you paste or type is uploaded or saved.
Frequently asked questions
Which regex flavour does this tester use?
It uses your browser's own JavaScript RegExp engine, so a pattern that works here works the same in JavaScript, TypeScript and Node.js. Most syntax is shared with Python, PHP (PCRE) and Java, but features such as possessive quantifiers and atomic groups are not available in JavaScript.
Why does my regex only find the first match?
Without the g (global) flag, JavaScript stops at the first match. Turn on g to find every match. If ^ and $ should match at the start and end of each line rather than the whole text, also turn on m (multiline).
Why did the tester stop with a catastrophic backtracking message?
Some patterns, usually nested quantifiers like (a+)+ or (.*)*, can take exponential time on text that almost matches. The tester runs your regex in a background worker and stops it after 1.5 seconds so the page never freezes. Rewrite the pattern to remove the nested repetition, for example (a+)+ becomes a+.