Regex Tester
Regular expressions are the Swiss Army knife of text processing — form validation, log parsing, data cleaning, find-and-replace in code refactoring — regex is everywhere. But the syntax is dense and unforgiving; one wrong character and nothing matches. Real-time feedback is the most effective way to debug regex.
This tool provides real-time match highlighting, capture group display, match position tracking, and syntax error feedback. Supports all 6 flags: g, i, m, s, u, y. Enter a pattern and test text to see matches in milliseconds — WYSIWYG for regex.
//gm
📖 Regex Tester Guide
What Is a Regular Expression?
A regular expression (regex/regexp) is a pattern-matching syntax for strings. Invented in the 1950s by mathematician Stephen Kleene, regex is now built into virtually every programming language. Its core value: replace dozens of lines of string-handling code with a single expression — validate emails, extract IP addresses from logs, batch-replace date formats — all with one regex.6 Flags Explained
- g (global): Match all occurrences. Without g, only the first match is returned. Essential for search-and-replace.
- i (case-insensitive): /hello/i matches Hello, HELLO, heLLo.
- m (multiline): ^ and $ match the start/end of every line, not just the whole string.
- s (dotAll): Dot matches everything, including newlines. Without s, . does not match \n — one of the most common beginner mistakes.
- u (unicode): Enables \u{XXXXX} and Unicode property escapes (\p{Script=Han} for Chinese). Always enable when processing CJK or emoji.
- y (sticky): Match must start exactly at lastIndex. Rarely used; mainly for tokenizers.
Common Regex Patterns
Email: [\w.-]+@[\w.-]+\.\w+
Phone: 1[3-9]\d{9}
ID card: \d{17}[\dXx]
IP: \d{1,3}(\.\d{1,3}){3}
URL: https?://[^\s]+
Date (yyyy-mm-dd): \d{4}-\d{2}-\d{2}
Chinese: [\u4e00-\u9fa5]+
Blank line: ^\s*$
Common Mistakes
- Forgetting to escape special chars: . * + ? [ ] ( ) {{ }} ^ $ | \ / have special meaning. To match them literally, escape with \: match 1+1=2 with 1\+1=2.
- Greedy matching grabs too much: .* is greedy — it matches as much as possible. .* on ab matches everything, not each tag. Use .*? for lazy matching.
- Ignoring Unicode: \w matches [a-zA-Z0-9_] only, not Chinese. Add [\u4e00-\u9fa5] or use the u flag with Unicode properties.
- Catastrophic backtracking: Nested quantifiers like (a+)+b on "aaaaaaaaaaaa" (no b) cause exponential backtracking that freezes the browser. Avoid nested quantifiers.