Regex Tester, Online Regular Expression Testing, Regex Validator
- Related tools:
- Code Highlighter/Beautifier
- Online Markdown Editor
/
REGEX FLAGS
Don't return after first match
^ and $ match start/end of line
Case insensitive match
Dot matches newline
Match with full Unicode
Anchor to start position
Click /g button to select flags
# | Match | Index | Capture groups |
---|
Regular Expression Reference Guide
Validation Patterns
Basic Quantifiers
Pattern | Description |
---|---|
* |
0 or more times |
+ |
1 or more times |
? |
0 or 1 time |
{n} |
Exactly n times |
{n,} |
n or more times |
{n,m} |
Between n and m times |
Greedy vs Lazy
Pattern | Description |
---|---|
*? |
0 or more (lazy) |
+? |
1 or more (lazy) |
?? |
0 or 1 (lazy) |
{n,}? |
n or more (lazy) |
{n,m}? |
Between n and m (lazy) |
Character Classes
Pattern | Description |
---|---|
. |
Any character except newline |
\d |
Digit [0-9] |
\D |
Not a digit [^0-9] |
\w |
Word character [A-Za-z0-9_] |
\W |
Not a word character [^A-Za-z0-9_] |
\s |
Whitespace (space, tab, newline, etc.) |
\S |
Not whitespace |
[abc] |
Match any character in set |
[^abc] |
Match any character not in set |
[a-z] |
Match any character in range |
Anchors
Pattern | Description |
---|---|
^ |
Start of string or line |
$ |
End of string or line |
\b |
Word boundary |
\B |
Not word boundary |
Escape Sequences
Pattern | Description |
---|---|
\n |
Newline |
\r |
Carriage return |
\t |
Tab |
\\ |
Backslash |
\. |
Escape special characters (. * + ? ^ $ [ ] { } ( ) | \) |
Groups & Capturing
Pattern | Description |
---|---|
(abc) |
Capturing group, can reference with $1, $2, etc. |
(?:abc) |
Non-capturing group, groups but doesn't capture |
(?<name>abc) |
Named capturing group |
\1, \2 |
Backreference to captured group |
$1, $2 |
Reference captured groups in replacement |
Lookaround Assertions
Pattern | Description |
---|---|
(?=abc) |
Positive lookahead |
(?!abc) |
Negative lookahead |
(?<=abc) |
Positive lookbehind |
(?<!abc) |
Negative lookbehind |
(a|b) |
Alternation, match a or b |