Regex Syntax Quick Reference
| Pattern | Description | Example |
|---|---|---|
. | Any character except newline | a.c matches "abc", "a1c" |
* | Zero or more of the preceding | ab*c matches "ac", "abc", "abbc" |
+ | One or more of the preceding | ab+c matches "abc", "abbc" (not "ac") |
? | Zero or one of the preceding | colou?r matches "color", "colour" |
^ | Start of string (or line with m flag) | ^Hello matches "Hello world" |
$ | End of string (or line with m flag) | world$ matches "Hello world" |
[abc] | Character class (any of a, b, or c) | [aeiou] matches any vowel |
(abc) | Capturing group | (\w+)@(\w+) captures user and domain |
{n,m} | Between n and m repetitions | a{2,4} matches "aa", "aaa", "aaaa" |
| | Alternation (or) | cat|dog matches "cat" or "dog" |
\d | Any digit (0-9) | \d{3} matches "123" |
\w | Word character (letter, digit, underscore) | \w+ matches "hello_123" |
\s | Whitespace (space, tab, newline) | \s+ matches spaces between words |
\b | Word boundary | \bword\b matches whole word only |
Common Regex Patterns
| Use Case | Pattern | Notes |
|---|---|---|
| Email address | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | Basic validation, not RFC 5322 compliant |
| URL | https?:\/\/[^\s/$.?#].[^\s]* | Matches http and https URLs |
| Phone number (US) | \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} | Matches (123) 456-7890, 123-456-7890, etc. |
| IP address (IPv4) | \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b | Does not validate octets are 0-255 |
| Date (YYYY-MM-DD) | \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) | ISO 8601 date format |
Flags Explained
| Flag | Name | Effect |
|---|---|---|
g | Global | Find all matches, not just the first one |
i | Case-insensitive | Match uppercase and lowercase letters interchangeably |
m | Multiline | ^ and $ match start/end of each line, not just the whole string |
s | DotAll | . matches newline characters as well |
u | Unicode | Enables full Unicode support and strict syntax |
FAQ
Is my data safe?
Yes. The regex testing happens entirely in your browser using JavaScript's built-in RegExp engine. No text or patterns are sent to any server.
Which regex flavor does this use?
This tool uses JavaScript's native regular expression engine (ECMAScript). Syntax may differ slightly from PCRE (PHP, Python) or POSIX regex in features like lookbehinds and named groups.
Why do I get "invalid regular expression" errors?
Common causes include unescaped special characters (like parentheses or brackets that aren't closed), invalid quantifiers, or using syntax not supported in JavaScript regex. Check that all opening brackets and parentheses have matching closing ones.
What are capture groups?
Parentheses () in a regex create capture groups. They let you extract specific parts of a match. For example, (\d+)-(\d+)on "2024-01" captures "2024" as group 1 and "01" as group 2.
How do I match a literal special character?
Escape it with a backslash. To match a literal dot, use \.. To match a literal backslash, use \\. Characters that need escaping: . * + ? ^ $ { } [ ] ( ) | \