What is a Regular Expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. Itβs used to find, match, and extract text that follows a specific format β like phone numbers, email addresses, dates, or any pattern you can describe. Regular expressions are supported in nearly every programming language and text editor.
While powerful, regex syntax can be tricky to get right. A small mistake β a missing backslash, a misplaced quantifier β can make a pattern match nothing at all, or worse, match the wrong things. Testing patterns live as you write them makes the process much faster and less error-prone.
What Does This Tool Do?
This tool lets you write a regular expression and test it against sample text in real time. All matches are highlighted as you type, and any capture groups are shown separately. You can also test different flags like global matching, case-insensitivity, and multiline mode.
How to Use This Tool
- Enter your regular expression in the pattern field.
- Paste or type the text you want to test in the input area.
- Matches are highlighted instantly as you type.
- Captured groups are shown below the match list.
- Toggle flags (global, case-insensitive, multiline) as needed.
Common Use Cases
- Validating formats: Test a pattern for email addresses, phone numbers, postal codes, or dates.
- Extracting data: Build a regex to pull specific fields from log files or structured text.
- Find and replace: Write and test a pattern before using it in your editor or code.
- Learning regex: Experiment with patterns and immediately see what they match.
Regex Syntax Cheat Sheet
| Pattern | Matches |
|---|---|
. | any single character (except newline) |
\d / \D | a digit / anything that isnβt a digit |
\w / \W | a word character (letter, digit, _) / anything else |
\s / \S | whitespace / non-whitespace |
[abc] | one of a, b, or c |
[^abc] | any character except a, b, c |
a* / a+ / a? | zero or more / one or more / zero or one a |
a{2,4} | between two and four as |
^ / $ | start / end of line (or string without m flag) |
| `(cat | dog)` |
(?:β¦) | group without capturing |
(?<name>β¦) | named capture group |
(?=β¦) / (?!β¦) | lookahead: followed by / not followed by |
\b | word boundary |
Handy Patterns to Start From
| Goal | Pattern |
|---|---|
| Email (pragmatic) | [\w.+-]+@[\w-]+\.[\w.]+ |
| URL | https?://[^\s]+ |
| ISO date (2026-07-04) | \d{4}-\d{2}-\d{2} |
| Time (14:30) | `([01]\d |
| Integer or decimal | -?\d+(\.\d+)? |
| HEX color | #(?:[0-9a-fA-F]{3}){1,2}\b |
| Duplicate words | \b(\w+)\s+\1\b |
| Trailing whitespace | [ \t]+$ (with m flag) |
These are practical starting points, not bulletproof validators β adapt them to your data. For email in particular, full RFC-compliant validation is famously impractical with regex alone; validate the format loosely and confirm with a verification email.
Understanding Flags
- g (global) β find all matches instead of stopping at the first.
- i (ignore case) β
Amatchesa. - m (multiline) β
^and$match at every line break, not just the start and end of the whole text. - s (dotAll) β
.also matches newlines. - u (unicode) β enables correct handling of characters outside the basic range, including emoji.
Frequently Asked Questions
What regex flavor does this tool use?
This tool uses JavaScriptβs built-in regular expression engine, which follows the ECMAScript standard. It supports most common regex features including groups, lookaheads, and character classes.
Why isn't my pattern matching anything?
Common causes: forgetting the global (g) flag for multiple matches, incorrect escaping of special characters, or using a feature not supported by the JavaScript engine (like lookbehinds on older browsers).
Is my data private?
Yes. All pattern matching runs locally in your browser β no text is sent to any server.
What is catastrophic backtracking?
Certain patterns β typically nested quantifiers like (a+)+ β can force the regex engine to try an exponential number of combinations on non-matching input, freezing the page or, on a server, enabling a denial-of-service (ReDoS). If a pattern feels slow, avoid nesting quantifiers and prefer more specific character classes over .*.
Do I need to escape special characters?
Yes β characters that have regex meaning (. * + ? ( ) [ ] { } | ^ $ \ /) must be escaped with a backslash to match literally. To find the text 3.50, write 3\.50; otherwise the . matches any character and 3450 would also match.