What a Regex Tester Does
A regular expression (regex) is a pattern for matching strings of text. \d+ matches one-or-more digits. [a-z]{3,5} matches 3-5 lowercase letters. Regexes power form validation, search-and-replace, log parsing, URL routing, and much more — but they're notoriously hard to write correctly without testing.
The Microapp Regex Tester lets you write a regex and test it against sample text in real time. Matches highlight in the input as you type. Shows capture groups, supports all standard JavaScript regex flags, and runs entirely in your browser — your patterns and test text never leave your device.
How to Use It
- Enter your regex pattern in the pattern input (without surrounding slashes — flags go in the separate flags field).
- Enter or paste sample text into the test area.
- Matches highlight as you type. Capture groups appear below.
- Toggle flags as needed:
g(global, find all),i(case-insensitive),m(multiline),s(dotall),u(unicode),y(sticky).
(\w+)@(\w+\.\w+) with flag gText:
Email me at [email protected] or [email protected]Matches:
[email protected], [email protected]Capture group 1: usernames (alice, bob). Capture group 2: domains (example.com, test.org).
The Most-Used Regex Patterns
| What you want to match | Pattern | Notes |
|---|---|---|
| Any digit | \d | Equivalent to [0-9] |
| Any letter | [a-zA-Z] | \w matches word chars (letters + digits + _) |
| One or more | + | \d+ = at least 1 digit |
| Zero or more | * | \d* = 0+ digits |
| Optional | ? | colou?r matches both color and colour |
| Exact count | {n} | \d{4} = exactly 4 digits (e.g. years) |
| Range | {n,m} | \d{3,5} = 3 to 5 digits |
| Beginning of line | ^ | With m flag, matches start of every line |
| End of line | $ | With m flag, matches end of every line |
| Capture group | ( ) | Captured text accessible as $1, $2, etc. |
| Non-capturing group | (?: ) | Group for alternation/grouping without capturing |
| Alternation | | | cat|dog matches cat or dog |
| Word boundary | \b | \bword\b matches word as a whole word |
Common Regex Mistakes
Forgetting to escape special characters. ., *, +, ?, (, ), [, ], {, }, ^, $, |, \ all have special meaning. To match them literally, escape with backslash: \. matches a literal period.
Greedy vs lazy matching. .* is greedy — matches as much as possible. .*? is lazy — matches as little as possible. The difference matters in HTML parsing or any text with multiple potential closing markers.
Email validation overkill. The "perfect" email regex is hundreds of characters and still doesn't match every edge case. For practical validation, use ^[^\s@]+@[^\s@]+\.[^\s@]+$ (no spaces, has @, has a dot in the domain) and verify with an actual confirmation email.
Anchors and the m flag. Without m, ^ matches only the start of the entire input. With m, it matches the start of each line. Forgetting m when working with multiline input is a common bug.
When Regex Is the Wrong Tool
Regex is great for pattern matching in roughly-structured text. It's bad at:
- Parsing HTML. HTML can nest arbitrarily; regex can't handle nested structures. Use a real HTML parser (
cheerio,jsdom,BeautifulSoup). - Parsing JSON, XML, CSV. Same reason — these have structure that regex can't reliably model. Use
JSON.parse, an XML parser, or a CSV parser. - Handling natural-language ambiguity. Don't try to regex your way through prose. Use NLP libraries.
Related Tools
For testing and formatting JSON data alongside regex work, use the JSON Formatter. For URL-encoding strings to embed in regex patterns or test data, see the URL Encoder/Decoder. For converting case (often needed before regex matching with the i flag isn't enough), the Case Converter is the right tool.