Testador de Regex
Test regular expressions with live highlighting and match information
Regular Expression
Test String
Results
Sobre esta ferramenta
A regular expression is a compact description of a text pattern, and the reason they are notoriously hard is that a wrong regex rarely fails loudly - it quietly matches slightly too much or too little, and the bug surfaces weeks later on data nobody tested. Testing against real sample text is the only reliable way to write one, which is what this tool is for. A few concepts carry most of the weight. Character classes such as \d, \w and \s match digits, word characters and whitespace. Quantifiers - *, +, ?, {2,5} - say how many times. Anchors ^ and $ tie the match to the start and end. Groups in parentheses capture the parts you want to extract. The one behaviour that catches almost everyone is greediness: quantifiers grab as much as possible by default, so .* in an HTML pattern swallows the whole line rather than stopping at the first closing tag. Adding ? after the quantifier makes it lazy and fixes it. Matching happens in your browser.
Como usar esta ferramenta
- Write your patternEnter the regex without surrounding slashes. Syntax errors are reported as you type rather than after you run it.
- Set the flagsg finds every match rather than the first, i ignores case, m makes ^ and $ match at line boundaries.
- Paste realistic test textInclude the awkward cases - empty values, unusual formats, things that should NOT match. That is where patterns actually break.
- Read the highlightingMatches are highlighted in place and captured groups listed separately, so you can see exactly what would be extracted.
Por que usar
- Live highlighting shows what matches as you type, which is far faster than running code repeatedly.
- Captured groups are listed separately, so you can confirm you are extracting the right part.
- Flags can be toggled instantly to see how they change behaviour.
- Runs in your browser, so log extracts and real data used as test input are never uploaded.
- No account or usage limit.
Usos comuns
- Building a validation pattern for emails, phone numbers or postcodes before putting it in a form.
- Extracting fields from log lines or unstructured text.
- Writing a find-and-replace pattern for a bulk edit across a codebase.
- Debugging a pattern that works on most inputs but fails on a specific one.
- Learning regex by watching what each change does to the highlighting.
Dicas para melhores resultados
- Test with text that should NOT match, not just text that should. Over-matching is the more common bug and the harder one to notice.
- Use lazy quantifiers - *? and +? - when matching between delimiters, or the pattern will run to the last one on the line rather than the first.
- Escape dots outside character classes. An unescaped . matches any character, which quietly makes patterns far broader than intended.
- Prefer specific classes over the dot. [0-9]{4} says what you mean; .{4} matches four of anything.
- For email validation, a simple pattern plus an actual send is more reliable than a complex regex - the full RFC-compliant email regex is thousands of characters and still not worth using.
Erros a evitar
- Forgetting the g flag and wondering why only the first match is found.
- Using .* where .*? was needed, so the match runs greedily to the end of the line.
- Leaving a dot unescaped in a domain or filename pattern, making it match almost anything.
- Trying to parse HTML or JSON with regex. Both are nested structures that regular expressions fundamentally cannot handle reliably - use a parser.
- Writing a catastrophically backtracking pattern - nested quantifiers like (a+)+ can hang on certain inputs, which is a real denial-of-service vector.
- Assuming a pattern that works here behaves identically in another language. Lookbehind, named groups and Unicode handling all differ.
Opções disponíveis
- Pattern
- Flags
- Live match highlighting
Perguntas frequentes
Enter your pattern above, set the flags you need and paste sample text. Matches are highlighted live and captured groups listed, so you can see precisely what the pattern does.
Yes. No account, no limit, and your test data stays in your browser.
JavaScript's, which covers the syntax shared by most modern languages. Advanced features differ - Python, PHP, Java and Go each vary on lookbehind, named groups and Unicode properties - so verify anything exotic in your target environment.
g finds all matches instead of stopping at the first, i makes matching case-insensitive, m makes ^ and $ match at each line rather than only at the start and end of the whole text, and s makes . match newlines too.
Almost always greediness. Quantifiers like * and + take as much as they can, so .* runs to the end of the line. Add ? to make them lazy - .*? stops at the first possible match instead.
Greedy takes the longest match possible; lazy takes the shortest. Matching <.*> against "<a><b>" gives the whole string; <.*?> gives just "<a>".
You should not. HTML nests arbitrarily and regular expressions cannot describe nested structures reliably, so any pattern will break on valid input. Use an HTML parser instead - regex is fine only for very constrained, known-format snippets.
No. Matching runs in your browser, which matters because sample text is often a real log extract or customer data.
As pessoas também pesquisam
- regex tester online free
- regex101 alternative
- test regular expression javascript
- regex cheat sheet
- regex for email validation
- greedy vs lazy regex
- regex match all occurrences