Regex Tester
Test regular expressions against sample text with live match highlighting, groups and flags. A free regex tester; nothing is uploaded.
Quick Patterns
knowledge hub
Character Classes
. | Any character except newline |
\d | Digit (0-9) |
\D | Not a digit |
\w | Word character (a-z, A-Z, 0-9, _) |
\W | Not a word character |
\s | Whitespace (space, tab, newline) |
\S | Not whitespace |
[abc] | Any of a, b, or c |
[^abc] | Not a, b, or c |
[a-z] | Character range a to z |
Quantifiers
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
{3} | Exactly 3 |
{3,} | 3 or more |
{3,5} | Between 3 and 5 |
*? | 0 or more (lazy) |
+? | 1 or more (lazy) |
?? | 0 or 1 (lazy) |
Anchors & Boundaries
^ | Start of string/line |
$ | End of string/line |
\b | Word boundary |
\B | Not a word boundary |
Groups & Lookaround
(abc) | Capture group |
(?:abc) | Non-capturing group |
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(?<!abc) | Negative lookbehind |
a|b | a or b |
Special Characters
\ | Escape special character |
\n | Newline |
\r | Carriage return |
\t | Tab |
\0 | Null character |
Flags
g | Global - Find all matches |
i | Case-insensitive |
m | Multiline - ^ and $ match line boundaries |
s | Dot-all - . matches newlines |
u | Unicode |
y | Sticky - Match from lastIndex |
Tips
- Use non-capturing groups
(?:...)when you don't need to extract the matched text - Be specific - Use
[0-9]instead of.when matching digits - Escape special chars - Use
\before. * + ? ^ $ { } [ ] ( ) | \ - Test edge cases - Empty strings, special characters, very long inputs
- Use anchors -
^and$to match entire string, not just part of it - Lazy quantifiers - Use
*?or+?to match as little as possible
Test a regular expression as you type
Enter a pattern, toggle the flags and paste some text: matches are highlighted in the text and listed underneath with their position and capture groups. The engine is the browser's own JavaScript RegExp, so what passes here behaves identically in Node or a browser script, including lookbehind, named groups and Unicode property escapes where the browser supports them.
All six JavaScript flags are available as toggles: g for every match rather than the first, i for case-insensitive, m so ^ and $ match at line breaks, s so the dot matches newlines, u for Unicode mode and y for sticky matching. An invalid pattern shows the parser's error message rather than silently matching nothing. The copy button exports the expression as /pattern/flags, ready to paste into code.
A set of quick patterns covers the usual starting points: email addresses, URLs, dates in YYYY-MM-DD, 24-hour times, IPv4 and IPv6 addresses, hex colours, usernames, Markdown links and file extensions. They are deliberately plain so they can be read and adapted rather than treated as the last word; a fully RFC-compliant email regex runs to several hundred characters and is rarely worth it.
Frequently asked questions
Is my regex or test text sent to a server?
No. Matching runs in your browser with the built-in RegExp engine; nothing is submitted, logged or saved.
Which regex flavour is this?
JavaScript (ECMAScript). It is close to PCRE and Python for everyday patterns, but lacks possessive quantifiers, atomic groups and the \A and \Z anchors, and conditionals are not supported.
Why does my pattern only match once?
The g flag is off. Without it a JavaScript regex stops at the first match; turn g on to list every occurrence.
Why does ^ not match the start of each line?
By default ^ and $ anchor to the start and end of the whole string. Enable the m flag and they also match at every line break.
Can I test a search-and-replace?
Not here; the tool shows matches and capture groups only. Use the group numbers it reports to build the replacement string in your editor or code.