Regex Tester
Test JavaScript regular expressions with live match highlighting, replace mode, and a pattern library.
/ /
Regex Quick Reference
Character Classes
.Any character except newline\dDigit [0-9]\DNon-digit\wWord char [a-zA-Z0-9_]\WNon-word character\sWhitespace[abc]Character set[^abc]Negated set[a-z]RangeAnchors
^Start of string/line$End of string/line\bWord boundary\BNon-word boundaryQuantifiers
*0 or more (greedy)+1 or more (greedy)?0 or 1 (optional){n}Exactly n times{n,m}Between n and m times*?0 or more (lazy)Groups & Alternation
(abc)Capture group(?:abc)Non-capturing groupa|bAlternation (a or b)(?=abc)Positive lookahead(?!abc)Negative lookahead\1Backreference to group 1Click any pattern to load it into the Pattern field above.
Regular expression basics
A regular expression (regex) is a sequence of characters that defines a search pattern. This tester
uses JavaScript's native RegExp engine, which follows the ECMAScript specification.
.— matches any character except newline (usesflag for newlines).*/+/?— 0+, 1+, or 0–1 repetitions. Add?after for non-greedy (*?,+?).{n,m}— matches between n and m repetitions.^/$— start / end of string (or line withmflag).[abc]/[^abc]— character class / negated character class.(…)— capturing group.(?:…)is non-capturing.\d \w \s— digit, word character, whitespace. Uppercase negates.\b— word boundary.
Regex flags
g(global) — find all matches, not just the first.i(case insensitive) —Amatchesa.m(multiline) —^and$match the start/end of each line, not just the whole string.s(dot-all) —.matches newline characters as well.u(unicode) — treat the pattern as a sequence of Unicode code points.
Using Replace mode
Switch to the Replace tab to preview substitutions live. The replacement string supports
JavaScript's String.prototype.replace() syntax:
$1,$2, … — insert the text of capture group 1, 2, …$&— insert the entire matched substring.$`— insert the string before the match.$'— insert the string after the match.$$— insert a literal$.
With the g flag enabled all occurrences are replaced; without it only the first match is substituted.
Common regex patterns
- Email (basic)
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} - URL
https?://[^\s/$.?#].[^\s]* - IPv4
\b(?:\d{1,3}\.){3}\d{1,3}\b - Hex color
#(?:[0-9a-fA-F]{3}){1,2} - ISO date
\d{4}-\d{2}-\d{2} - Integer
-?\d+ - Decimal
-?\d+(?:\.\d+)? - Whitespace trim
^\s+|\s+$