.* Regex Tester Online — Test Regular Expressions
Test regular expressions with live match highlighting. See all matches, capture groups, and positions. Supports g, i, m, s flags. Free online regex tester.
Enter your regex pattern and test string, then see all matches highlighted in real-time. Capture groups are shown with their indices. Toggle flags (global, ignore-case, multiline, dotAll) and see results update instantly. Uses JavaScript's native RegExp engine.
How to Use
Enter a pattern
Type your regular expression in the pattern field. Use the checkboxes to enable flags: g (global), i (ignore case), m (multiline), s (dotAll).
Add your test string
Paste or type the string you want to test in the Test String area. All matches are highlighted live as you type.
Inspect matches
See the total match count, each match with its position, and any capture groups. Copy the verified pattern to use in your project.
Frequently Asked Questions
Complete Guide: Regex Tester
What Is a Regular Expression and Why It Matters
A regular expression (regex) is a sequence of characters that defines a search pattern. The syntax traces back to Stephen Kleene's 1956 mathematical formalization of regular languages, implemented practically by Ken Thompson in 1968 for UNIX grep. Every modern programming language — JavaScript, Python, Go, Java, Rust — has a regex engine, and most use a variant of the PCRE (Perl-Compatible Regular Expressions) syntax.
Regex is indispensable for: form validation (email, phone, postal code), log parsing (extracting timestamps and error codes from millions of lines), search-and-replace in code editors, URL routing patterns, and data extraction from unstructured text. A well-written regex replaces dozens of lines of string manipulation code. A poorly-written one causes catastrophic backtracking that can hang a server under malicious input.
The learning curve is steep because regex patterns can look like line noise — /^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,28}$/ — but the underlying rules are a small finite set. Master those rules and any pattern becomes readable.
How to Use the Regex Tester
- Enter your pattern in the pattern field (without surrounding slashes — the tool adds those).
- Set flags using the checkboxes:
g(global — find all matches, not just first),i(case-insensitive),m(multiline —^/$match line boundaries),s(dotAll —.matches newlines too). - Paste your test string in the text area. All matches highlight in real-time.
- Inspect the match list — each match shows its start/end index and any capture group values.
- Copy the verified pattern for use in your code.
Code Examples
// JavaScript: basic match and capture groups
const datePattern = /(\d{4})-(\d{2})-(\d{2})/g;
const str = 'Events: 2026-01-15, 2026-03-22';
for (const match of str.matchAll(datePattern)) {
console.log(`Year: ${match[1]}, Month: ${match[2]}, Day: ${match[3]}`);
}
// Named capture groups (ES2018+) — far more readable
const namedDate = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const { year, month, day } = '2026-05-08'.match(namedDate).groups;
// Lookahead / Lookbehind: find prices without including the $ sign
const pricePattern = /(?<=\$)\d+(\.\d{2})?/g;
'$12.99, $5, $199.00'.match(pricePattern); // ['12.99', '5', '199.00']
// Email validation (pragmatic — not RFC 5322 perfect)
const emailRx = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/i;
// URL slug validation
const slugRx = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
Common Mistakes to Avoid
- Catastrophic backtracking — Nested quantifiers like
(a+)+or(\w+\s?)+can cause exponential time complexity on certain inputs. Test with adversarial strings before deploying user-facing validation. - Forgetting anchors — Without
^and$,/\d+/matches "123" anywhere in "abc123xyz". Always anchor validation patterns. - Greedy vs lazy quantifiers —
.*is greedy (matches as much as possible). Use.*?for lazy (matches as little as possible) when extracting content between tags. - Trying to parse HTML or JSON with regex — Regex cannot handle recursive structures. Use a proper HTML parser (DOMParser) or JSON.parse instead.
- Not escaping metacharacters — Characters like
. * + ? ( ) [ ] { } \ ^ $ |have special meaning. To match them literally, escape with\. In JavaScript:str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'). - Flag assumptions —
^and$match the whole string by default, but only line boundaries when themflag is set. The behavior change is subtle and causes hard-to-debug mismatches.
Comparison with Alternatives
String methods (.includes(), .startsWith(), .split()) are readable and fast for simple cases — prefer them when regex would be overkill. Parser combinator libraries (like Parsimmon for JS, pyparsing for Python) handle recursive grammars that regex cannot. Full-text search engines (Elasticsearch, PostgreSQL tsvector) are better for searching large text corpuses than regex scanning. Specialized validators (like validator.js) handle edge cases in email, URL, and credit card validation better than hand-rolled regex.
After validating your regex pattern, use the Text Diff tool to compare text transformations, or the Case Converter for systematic string manipulations.
Pro Tips
- Named groups for maintainability:
(?<year>\d{4})beats(\d{4})— the group's purpose is self-documenting and accessible asmatch.groups.year. - Precompile regex outside loops: In JavaScript,
const rx = /pattern/g;outside the loop and then reset withrx.lastIndex = 0is faster than creating a new regex on each iteration. - Test ReDoS vulnerability: Before deploying a user-facing regex, test it with a string of 100+ repeated characters that partially matches the pattern. If it hangs, you have a ReDoS vulnerability.
- Use verbose mode in Python:
re.compile(r'''pattern''', re.VERBOSE)allows comments and whitespace for readability in complex patterns.