About this tool
Regular Expressions (Regex) are the industry standard for string pattern matching, data extraction, and form input validation across all programming languages. However, intricate regex syntax can be notoriously difficult to craft and debug. This tool offers real-time match highlighting, capture group extraction, modifier flags toggling, and an extensive library of production-ready patterns.
How to Use This Tool (Step-by-Step)
Input Regular Expression & Flags
Type your pattern into the regex bar and toggle needed flags: 'g' (global), 'i' (case-insensitive), 'm' (multiline), or 's' (dotAll).
Enter Test Text & Inspect Highlights
Paste your target string into the test area. All matches are instantly highlighted with color-coded tags and match counters.
Extract Capture Groups & Export Code
Review indexed capture groups and submatches in the breakdown table, then copy the verified expression directly into your application.
Instant Syntax Highlighting
Highlights matches and capture groups on the fly as you type, providing real-time syntax error feedback when brackets or quantifiers break.
Full Capture Group Inspection
Displays exact start/end match indices alongside numbered and named capture group contents, ideal for complex web scraping extractors.
100% Private Offline Testing
Regex compilation and testing happen entirely inside your browser's V8 engine. Test logs and user data remain strictly confidential.
Essential Patterns & ReDoS Prevention
- •Beware of Catastrophic Backtracking (ReDoS): Avoid nested quantifiers with overlapping sets like `(a+)+$`. Mismatched long inputs cause exponential iterations that freeze server CPUs.
- •Quick cheat sheet: US Phone: `^\+?1?\s*\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$`; IPv4: standard 4-octet regex; Strong password: `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$`.
- •Use non-capturing groups `(?:...)` for speed: If you only need grouping for a quantifier without extracting matches, `(?:...)` saves memory and speeds up matching.
Code & Transformation Examples
Email Extraction with Capture Groups
([a-zA-Z0-9_.+-]+)@([a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)• 全文匹配 (Full Match): "[email protected]"
• 捕获组 1 (用户名): "support"
• 捕获组 2 (域名): "example.com"* Parentheses () form capture groups to extract specific sub-components.
Native Implementation across Languages
const regex = /^[a-zA-Z0-9_]{4,16}$/;
const isValid = regex.test("my_username");
const matches = "abc-123".match(/(\w+)-(\d+)/);
console.log(matches[1], matches[2]); // abc, 123import re
pattern = r'^[a-zA-Z0-9_]{4,16}$'
is_valid = bool(re.match(pattern, "my_username"))
m = re.search(r'(\w+)-(\d+)', "abc-123")
print(m.group(1), m.group(2)) # abc, 123* In JS, `regex.test()` is significantly faster than `.match()` for pure boolean validation.
Frequently Asked Questions
Q: What do regex flags g, i, m, and s stand for?
A: g: global (find all matches rather than stopping at the first); i: ignore case; m: multiline (^ and $ match line boundaries); s: dotAll (allows '.' to match newline characters).
Q: What is the difference between greedy and lazy matching?
A: Standard quantifiers (*, +) are greedy, consuming the longest possible match. Adding a '?' (*?, +?) makes them lazy, stopping at the shortest valid match.
Q: Why does regex behave differently across programming languages?
A: Engines vary: JavaScript adheres to ECMA-262, Python uses its re module, and PHP/Go/Nginx use PCRE or RE2. Advanced features like lookbehinds or Unicode properties may differ.