Regex tester
Test a JavaScript-flavour regular expression against sample text, with live match highlighting.
Enter a pattern and some text; matches highlight instantly and the count updates as you type. Everything runs in your browser.
↳ Runs entirely in your browser. Nothing you type here is sent to us or anyone else.
Regex in 60 seconds
A regular expression describes a text pattern. Most characters match themselves; a handful are “metacharacters” with special meaning. This tester uses the JavaScript regex engine, which is close to (but not identical to) PCRE used by grep -P.
Common tokens
| Token | Matches |
|---|---|
. |
Any character (except newline) |
d / w / s |
Digit / word char / whitespace |
* + ? |
0+, 1+, 0 or 1 of the preceding |
{2,4} |
Between 2 and 4 repetitions |
[abc] |
Any one of a, b, c |
^ $ |
Start / end of line |
(...) |
A capture group |
Flags
| Flag | Effect |
|---|---|
g |
Global — find all matches, not just the first |
i |
Case-insensitive |
m |
Multiline — ^/$ match each line |
s |
Dot matches newlines too |
Handy patterns
| Goal | Pattern |
|---|---|
| Email (rough) | b[w.+-]+@[w-]+.[w.-]+b |
| IPv4 address | b(?:d{1,3}.){3}d{1,3}b |
| Hex colour | #[0-9a-fA-F]{6}b |
| ISO date | d{4}-d{2}-d{2} |
Regex on the command line
The same ideas power grep -E (extended) and grep -P (Perl-compatible), sed, and awk. Test here, then apply, e.g. grep -E "b[0-9]{1,3}(.[0-9]{1,3}){3}b" access.log.