Solve "Write-Once, Read-Never" regex problems.
Real-time testing, explanation, and code generation in one place.
| # | Content |
|---|---|
| ${{ i + 1 }} | {{ g }} |
A quick reference for common regular expression metacharacters and syntax. Bookmark this for your development needs.
| Symbol | Meaning | Example |
|---|---|---|
| . | Any character (except newline) | a.c → abc, aXc |
| \d | Digit (0-9) | \d{3} → 123 |
| \w | Word character [a-zA-Z0-9_] | \w+ → user_id |
| \s | Whitespace (space, tab, newline) | |
| [ ] | Character class (any of these) | [abc] → a, b, or c |
| [^ ] | Negation (not these) | [^0-9] → Non-digit |
| | | OR (Alternative) | jpg|png |
| \ | Escape character | \. → Literal dot |
| Symbol | Meaning | Example |
|---|---|---|
| * | 0 or more times | a* → (empty), a, aa... |
| + | 1 or more times | a+ → a, aa, aaa... |
| ? | 0 or 1 time (Optional) | https? → http, https |
| {n} | Exactly n times | \d{4} → 2025 |
| {n,} | n or more times | \d{8,} → 8+ digits |
| {n,m} | Between n and m times | \d{2,4} → 2 to 4 digits |
| Symbol | Meaning | Example |
|---|---|---|
| ^ | Start of line/string | ^http → Starts with http |
| $ | End of line/string | jpg$ → Ends with jpg |
Options specified after the regex pattern (e.g., /pattern/g). You can input these in the small box to the right.
| Flag | Name | Behavior |
|---|---|---|
| g | Global | Find all matches rather than stopping after the first match. |
| i | Ignore Case | Case-insensitive search (matches both 'A' and 'a'). |
| m | Multiline | ^ and $ match start/end of each line, not just the whole string. |
| Use Case | Pattern | Note |
|---|---|---|
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ | Basic validation | |
| US Zip Code | ^\d{5}(-\d{4})?$ | 5 digits or 5+4 |
| Phone (US) | ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ | Allows (123) 456-7890 |
| Date (ISO) | ^\d{4}-\d{2}-\d{2}$ | YYYY-MM-DD |
| URL | https?://[\w!?/+\-_~=;.,*&@#$%()'[\]]+ | Starts with http/s |
| Password (Strong) | ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$ | 8+ chars, upper, lower, digit |
| Username | ^[a-zA-Z0-9_-]{3,16}$ | Alphanumeric, 3-16 chars |
| Integer | ^\d+$ | Numbers only |
| Hex Color | ^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$ | #ffffff or #fff |
| Slug | ^[a-z0-9]+(?:-[a-z0-9]+)*$ | URL-friendly text |
By default, Regex stops searching after finding the first match. To find all instances in the text, you must enable the Global flag. Enter g in the small input box on the right side of the main regex input.
Capture groups are parts of your pattern enclosed in parentheses ( ). They allow you to isolate and extract specific parts of the matched text.
For example, in the pattern (\d{4})-(\d{2}), $1 would contain the year and $2 would contain the month. This is useful for data extraction and replacement.
This tool runs in the browser and uses the JavaScript regex engine. While basic syntax (like \d, +, *) is standard across PHP, Python, and Java, some advanced features (like lookbehinds) may differ.
Always double-check the specific documentation for your target language.