Regex Testing Guide: Master Regular Expressions From Basics to Advanced
Regular expressions are one of the most powerful text-processing tools available to developers — and one of the most intimidating. A well-crafted regex can validate an email address in microseconds, extract thousands of data points from a log file, or transform text with surgical precision. This guide breaks down regex syntax, teaches you to read and write patterns, and provides ready-to-use recipes for common tasks.
February 23, 2026
15 min read
Developer
Regex Syntax Fundamentals
Character Classes
| Pattern | Meaning | Example Match |
|---|---|---|
. | Any character (except newline) | a, Z, 5, @ |
\d | Digit (0-9) | 0, 5, 9 |
\w | Word character (a-z, A-Z, 0-9, _) | a, Z, 3, _ |
\s | Whitespace (space, tab, newline) | space, tab |
\D | Not a digit | a, @, space |
[abc] | Any of a, b, or c | a, b, c |
[^abc] | Not a, b, or c | d, 5, @ |
[a-z] | Any lowercase letter | a through z |
Quantifiers
| Quantifier | Meaning | Example |
|---|---|---|
* | 0 or more | ab*c matches ac, abc, abbc |
+ | 1 or more | ab+c matches abc, abbc |
? | 0 or 1 | colou?r matches color, colour |
{3} | Exactly 3 | \d{3} matches 123 |
{2,5} | Between 2 and 5 | \d{2,5} matches 12 to 12345 |
{3,} | 3 or more | \w{3,} matches abc, abcde |
Anchors and Boundaries
^— Start of string (or line in multiline mode)$— End of string (or line)\b— Word boundary (between \w and \W)
Test these patterns live with the regex tester.
Groups, Captures, and References
Parentheses create capturing groups for extracting specific parts of matches:
(abc)— Capture group: matches and remembers "abc"(?:abc)— Non-capturing group: groups without capturing(a|b)— Alternation: matches "a" or "b"\1— Backreference: matches the same text as group 1(?<name>...)— Named capture group
Lookaheads and Lookbehinds
Lookarounds match positions without consuming characters:
(?=...)— Positive lookahead: followed by pattern(?!...)— Negative lookahead: NOT followed by pattern(?<=...)— Positive lookbehind: preceded by pattern(?<!...)— Negative lookbehind: NOT preceded by pattern
Note: JavaScript supports variable-length lookbehinds since ES2018, but older environments may not. Always check browser/engine compatibility.
Common Regex Recipes
# Email (simple)
^[\w.-]+@[\w.-]+\.\w{2,}$
# URL
https?://[\w.-]+(?:/[\w./?%&=-]*)?
# Phone (US formats)
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
# IP Address
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
# Date (YYYY-MM-DD)
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
# Strong Password (8+ chars, upper, lower, digit, special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$
# HTML Tag
<([a-z]+)([^>]*)>(.*?)</\1>
Regex Developer Tools
Pattern Testing Toolkit:
- Regex Tester — Test patterns with live highlighting
- Text Replace — Find and replace with regex
- Text Extractor — Extract pattern matches
- Code Formatter — Format regex in code
- JSON Formatter — Format extracted data
- Email Validator — Validate email patterns
Frequently Asked Questions
A pattern language for matching text. Used for validation, data extraction, search-and-replace, and log parsing across all programming languages.
Greedy (default) matches as much as possible. Lazy (add ?) matches as little as possible. Use lazy for extracting content between delimiters.
Use an online regex tester to write and test patterns before production. Test both matching and non-matching inputs. Check for catastrophic backtracking.
Different engines (PCRE, JavaScript, Java, .NET) have varying feature support for lookbehinds, unicode, and flags. Always test in your target environment.
Dev Tools
- Regex Tester
- Text Replace
- Code Formatter
- Email Validator
Related Guides
- JSON Guide
- Docs Best Practices
- GitHub Markdown