¿Qué es Probador de Regex?
Regular expressions (regex) are patterns that match character combinations in strings. They are among the most powerful text processing tools in programming, but also among the most difficult to write correctly. Our Regex Tester lets you write a pattern, set flags, test it against sample text, and see all matches highlighted in real time — with no code compilation or developer console needed.
The tester supports the full JavaScript regular expression syntax including character classes, quantifiers, groups, lookaheads, lookbehinds, anchors, named groups, and all standard flags (global, case-insensitive, multiline, dotAll). Match details — position index, full match text, and captured groups — are shown for every match in an organized list below the test string.
Regex bugs are notoriously hard to diagnose because dense syntax and small mistakes produce dramatically different behavior. An incorrectly placed quantifier, a forgotten escape character, or a missing anchor can cause catastrophic backtracking, false positives, or completely missed matches. The real-time feedback loop catches these issues as you type, before the regex reaches production code.
Casos de uso
Aquí tienes las formas más comunes en que la gente usa Probador de Regex todos los días.
Input Validation
Email addresses, phone numbers, ZIP codes, URLs, dates, and passwords all have structural patterns validatable with regex. Build and test your validation pattern against both valid examples (must match) and invalid examples (must not match) before adding it to your code. Testing edge cases — emails with plus signs and subdomains, international phone formats, leap year dates — prevents validation logic that passes the happy path but fails on real-world input.
Data Extraction and Parsing
Extracting structured data from unstructured text — log parsing, HTML scraping, CSV processing, text analytics — relies heavily on regex. Write a pattern that captures exactly the fields you need, test against representative samples, and verify captured group values before deploying. The tester shows each capture group value separately, making group numbering verification straightforward.
Search and Replace Operations
Use Replace mode to test search-and-replace transformations before running them on real data. Test converting snake_case to camelCase, reformatting dates, stripping HTML tags, normalizing phone numbers, or any batch text transformation. Preview the replaced output on sample data before running the same regex in your code or text editor's find-and-replace.
URL Routing Pattern Design
Web frameworks use regex or regex-like patterns for URL routing. Design and test route patterns that match intended URL structures without accidentally matching unintended paths. Verify parameter capture groups extract correct path segments and that anchors (^ and $) prevent partial matches.
Log File Analysis
Server logs contain structured information (timestamps, IPs, paths, status codes, response times) extractable with regex. Build patterns against sample log lines, verify capture groups extract correct fields, and copy validated patterns to log analysis scripts or monitoring tools.
Code Refactoring with Search-and-Replace
Regex-powered find-and-replace is one of the highest-leverage refactoring tools. Rename a parameter across an entire file while avoiding partial matches, convert function call syntax between APIs, change date format strings, or update import paths. Test the pattern and replacement in the Regex Tester with representative code samples before running it across an entire codebase — a subtle error in the pattern can corrupt hundreds of files silently.
Ejemplos
Email Validation
Match valid email addresses while rejecting malformed ones.
Pattern: \b[\w.+\-]+@[\w\-]+\.[\w.\-]+\b
Test: "hello@example.com and test@invalid" Matches: hello@example.com Extract Dates in MM/DD/YYYY Format
Capture structured date components from unstructured text using named groups.
Pattern: (?<month>\d{2})/(?<day>\d{2})/(?<year>\d{4})
Test: "Meeting on 03/15/2025 and follow-up on 04/01/2025" Match 1: 03/15/2025 — month:03, day:15, year:2025
Match 2: 04/01/2025 — month:04, day:01, year:2025 Match and Capture Phone Number Components
Parse North American phone numbers in multiple formats into area code, prefix, and line number.
Pattern: \(?(?<area>\d{3})\)?[\s.\-]?(?<prefix>\d{3})[\s.\-]?(?<line>\d{4})
Test: "(555) 867-5309 555.123.4567 5558675309" Matches: 3 phone numbers with area, prefix, and line groups captured from each format Probador de Regex frente a grep / sed
Browser-based regex tester versus command-line tools for pattern matching.
| Característica | Toolorah | grep / sed |
|---|---|---|
| Visual match highlighting | Yes — real-time | No — text output only |
| Captured group display | Yes — per-match breakdown | With -P and special flags |
| Real-time feedback | Yes — updates as you type | Run command each time |
| No terminal required | Yes | Requires shell access |
| Regex flavor | JavaScript/ECMAScript | POSIX/PCRE (grep), POSIX (sed) |
| Process actual files | No — paste text only | Yes — full file and directory support |
| Replace mode | Yes — visual preview | Yes — sed s/pattern/replace/g |
Consejos para usar Probador de Regex
- Use \b (word boundary) to avoid partial matches: /cat/ matches "concatenate" but /\bcat\b/ only matches standalone "cat".
- Prefer specific character classes over .* — the dot matches everything and easily over-matches.
- Use non-capturing groups (?:...) when grouping is needed but group values are not — keeps group numbering clean.
- Test both valid examples (should match) AND invalid examples (should not match) — both directions of correctness matter.
- Avoid deeply nested quantifiers like (a+)+ — these can cause catastrophic backtracking that freezes the browser on long strings.
Preguntas frecuentes
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. Given "<b>Hello</b> <b>World</b>", the greedy pattern <b>.*</b> matches the entire string from the first opening tag to the last closing tag. The lazy pattern <b>.*?</b> matches each tag pair separately. Use lazy quantifiers when extracting individual matches from text containing the delimiter pattern multiple times.
What do the regex flags do?
g (global): find all matches, not just the first. i (case insensitive): match regardless of case. m (multiline): ^ and $ match start/end of each line rather than the whole string. s (dotAll): the dot matches any character including newlines (by default . does not match \n). Flags can be combined: /pattern/gi finds all matches case-insensitively. Our tester applies g automatically to show all matches; toggle other flags as needed for your use case.
What is a capture group?
A capture group is a portion of the pattern in parentheses that captures the matched text for extraction. In /(\d{4})-(\d{2})-(\d{2})/, three groups capture year, month, and day separately from the full date match. In JavaScript, match[1], match[2], match[3] access these groups. Named groups use (?<name>pattern) syntax and are accessed as match.groups.name. The tester displays all captured groups for each match, making group numbering and naming verification straightforward.
What is catastrophic backtracking?
Catastrophic backtracking occurs when a regex engine tries exponentially many ways to match a pattern before failing. It happens with nested quantifiers on overlapping character classes — for example, (a+)+ on a long string of "a" characters followed by a character the pattern cannot match. The engine tries all possible groupings before giving up, which can take seconds or minutes. Prevention: avoid nested quantifiers, use atomic groups or possessive quantifiers when available, and test patterns against strings designed to trigger worst-case backtracking.
How do I match a literal dot, asterisk, or other special character?
In regex, . * + ? ( ) [ ] { } ^ $ | \ are special metacharacters with specific meanings. To match them literally, escape with a backslash: \. matches a literal dot, \* matches a literal asterisk. In a character class [...], most metacharacters lose their special meaning — [.*+] matches a literal dot, asterisk, or plus sign. The exceptions inside character classes are ] \ ^ and -.
What is the difference between anchors and word boundaries?
^ anchors to the start of the string (or line in multiline mode). $ anchors to the end. \b is a word boundary — the position between a word character (\w) and a non-word character. /^hello$/ matches only the string "hello" (nothing before or after). /\bhello\b/ matches "hello" as a standalone word in any position in a string. Use ^ and $ for validating entire strings (email validation, format validation). Use \b for finding words within larger text.
Can regex match HTML reliably?
Regex can match simple, predictable HTML patterns — like extracting href values from anchor tags with a consistent format. However, HTML is not a regular language — it has nested, context-dependent structure that regex fundamentally cannot parse reliably. Regex on real-world HTML fails on: self-closing tags, optional attributes, different attribute quote styles, nested tags, HTML entities in attribute values, and multiline tags. For parsing HTML, use a proper HTML parser (DOMParser in the browser, BeautifulSoup in Python, Cheerio in Node.js) rather than regex.
What is the difference between JavaScript regex and Python/PCRE regex?
JavaScript regex (ECMAScript) and PCRE (Perl-Compatible Regular Expressions, used by Python, PHP, Ruby) are largely similar but have differences: JavaScript uses different syntax for named groups ((?<name>) vs Python's (?P<name>)), supports lookbehind only with fixed-width patterns in some versions, and lacks possessive quantifiers and atomic groups. Python's re module supports the same ?P<name> syntax and adds verbose mode (?x) for commented regex. PCRE supports \K (resets match start), recursive patterns, and conditionals not available in JavaScript regex.