Pule para o conteúdo principal
EverydayToolsSIMPLES • GRÁTIS • RÁPIDO
InícioCategorias
Ferramentas de busca...
  1. Home
  2. Tecnologia
  3. Regex Tester
Advertisement
Loading...
Advertisement
Loading...

Test and debug JavaScript regular expressions in real time

Regular expressions — commonly called regex or regexp — are one of the most powerful and versatile tools in a developer's or data analyst's toolkit. A regular expression is a sequence of characters that defines a search pattern. In a single concise expression, you can match a specific string, validate that user input conforms to a format like an email address or phone number, extract structured data from unstructured text, or perform sophisticated find-and-replace transformations. Despite their power, regular expressions have a well-earned reputation for being cryptic and difficult to debug, especially when a pattern is more than a few characters long. This Regex Tester removes the friction. As you type your pattern and test string, the tool instantly runs JavaScript's native RegExp engine against the input and highlights every match in real time. You see exactly what your pattern matches — which characters are captured, where in the string each match starts and ends, and how capturing groups extract sub-portions of the match. There is no submit button to press and no page reload to wait for; results appear within milliseconds of each keystroke. The tool supports all six JavaScript regex flags: **g** (global, find all matches rather than stopping at the first), **i** (case-insensitive matching), **m** (multiline, so `^` and `$` match at line boundaries rather than only at the start and end of the whole string), **s** (dotAll, so the `.` metacharacter matches newline characters), **u** (Unicode, enabling proper handling of Unicode code points and properties), and **y** (sticky, matching only from the `lastIndex` position). You can toggle any combination of flags with a single click. **Match Mode** is the default view. The highlighted test string shows every match visually marked, and a scrollable match details panel lists each match with its full text, start and end character positions, and the values of all numbered and named capturing groups. Clicking any match in the details panel or in the highlighted text cross-selects the item in both views. **Substitute Mode** lets you preview the result of a find-and-replace operation before running it in your code. Enter a replacement string that can include backreferences like `$1` (first capturing group), `$&` (the full match), `$`` (text before the match), and `$'` (text after the match). The substituted result updates live as you adjust the pattern, flags, or replacement. **Validate Mode** is designed for checking whether a pattern accepts or rejects a list of inputs. Paste a newline-separated list of values — email addresses, phone numbers, URLs, or any other strings — and the tool instantly shows a pass/fail indicator for each one. This is perfect for testing an input validation regex against a realistic set of test cases. The **Quick Reference Cheatsheet** is a compact, tab-organized reference covering the four main categories of regex syntax: Character Classes (`.`, `\d`, `\w`, `\s`, character sets, and ranges), Anchors (`^`, `$`, `\b` word boundary), Quantifiers (`*`, `+`, `?`, `{n,m}`, lazy variants), and Groups (capturing groups, non-capturing groups, named groups, lookaheads, lookbehinds, and backreferences). Clicking any token in the cheatsheet appends it directly to your pattern field, accelerating pattern construction. The **Common Patterns Library** provides a curated set of production-tested regex patterns for the most frequently needed use cases: email validation, HTTP/HTTPS URL matching, IPv4 address extraction, ISO 8601 date validation, US phone number matching, ZIP code detection, hex color code extraction, HTML tag matching, usernames, IPv6 addresses, Markdown links, and strong password enforcement. Click the Use button next to any pattern to instantly load it into the pattern field. A **coverage bar** shows what proportion of your test string is covered by matches — a useful sanity check when you are trying to match an entire document or want to confirm your pattern is not leaving large gaps. The **Export to CSV** button downloads all matches (with their index, start position, end position, length, and group values) as a comma-separated file that can be opened in Excel or Google Sheets for analysis. All processing happens entirely in your browser using JavaScript's built-in `RegExp` API. No data is sent to any server. The tool saves your last-used pattern and test string to browser `localStorage` so your work persists across page refreshes. You can also share your current pattern and test string via a URL that encodes the state in query parameters — useful for asking a colleague to look at a specific expression. Regular expressions are used across virtually every programming language and text processing tool: JavaScript, Python, Java, PHP, Ruby, Perl, Go, Rust, SQL, grep, sed, Sublime Text, VS Code, IntelliJ, and many more. While this tester uses the JavaScript engine (ECMAScript regex flavor), the core syntax is shared across almost all flavors. Understanding regex patterns thoroughly pays dividends for life — whether you are parsing log files, building form validators, writing data extraction scripts, or cleaning up messy datasets.

Understanding Regular Expressions

What Is a Regular Expression?

A regular expression is a formal pattern language for describing sets of strings. It is composed of literal characters (which match themselves exactly), metacharacters (which have special meaning, like `.` matching any character or `*` meaning 'zero or more'), character classes (sets of characters enclosed in square brackets), quantifiers (controlling how many times a preceding element may occur), anchors (constraining where in the string a match may occur), and groups (wrapping sub-expressions to capture their matched content or to apply quantifiers to them as a unit). Combined, these building blocks allow extraordinarily precise or flexible string matching. A pattern like `\b[A-Z]\w+@\w+\.\w{2,}\b` can match an email address starting with an uppercase letter in a sea of text — something that would take many lines of procedural code to replicate.

How Does the Regex Engine Work?

JavaScript's regex engine uses a non-deterministic finite automaton (NFA) model. Starting from the first character of the test string, the engine attempts to match the pattern character by character. When it encounters a choice point (such as a quantifier or an alternation), it tries all possibilities, backtracking if a path fails. Quantifiers like `*` and `+` are greedy by default — they consume as many characters as possible and only give back characters if needed to allow the overall match to succeed. Adding `?` after a quantifier makes it lazy (minimal match). Lookaheads (`(?=...)`) and lookbehinds (`(?<=...)`) assert that the surrounding context matches without consuming characters. The engine reports the first leftmost match (or all matches with the `g` flag), the positions of capturing groups, and named group values. Invalid patterns throw a SyntaxError which the tester catches and displays as an error message.

When Should You Use Regular Expressions?

Regular expressions excel at tasks involving pattern detection in text: form field validation (emails, phone numbers, ZIP codes, dates), data extraction from log files or scraped HTML, search-and-replace in code editors, tokenizing text into structured components, filtering lines from large text files, and enforcing naming conventions. They are the right tool when the problem is fundamentally about string patterns rather than structured data. They are a poor fit when the input format is recursive (HTML, XML, JSON, code), when the pattern logic is too complex for a one-liner, or when false positives must be strictly zero (in which case a purpose-built parser is safer). A good rule of thumb: if you need to write more than four or five non-trivial regex patterns in the same codebase, consider whether a parsing library would be more maintainable.

Limitations and Performance Notes

This tester uses the JavaScript ECMAScript regex flavor, which differs in some respects from PCRE (used by PHP, Perl, and many other tools), Python's `re` module, and .NET's regex engine. Key differences include: no support for possessive quantifiers or atomic groups in JavaScript, limited Unicode property escapes (added in ES2018 with the `u` flag), and no conditional patterns. Catastrophic backtracking is a real risk: patterns like `(a+)+` applied to a long string of non-matching characters can cause an exponential number of engine steps, freezing the browser tab. The tester limits matches to 500 per run and uses a debounce to avoid firing on every keystroke, but cannot protect against all catastrophic patterns. If your pattern takes more than a second to match, simplify or restructure it. The `u` flag enables proper Unicode handling but also makes the engine stricter — some patterns that work without `u` will throw an error when it is enabled.

How to Use

1

Enter Your Regex Pattern

Type or paste your regular expression into the pattern field (shown between the `/` delimiters). The active flags appear after the closing delimiter. As you type, matches update instantly in the results area below. If your pattern has a syntax error, a red error message appears below the field.

2

Toggle Flags and Add Test Text

Click the flag buttons (g, i, m, s, u) to toggle each one on or off. Then type or paste your test string in the textarea below. The tool highlights every match in real time and shows a coverage bar indicating what percentage of the test string is covered by matches.

3

Inspect Match Details and Groups

Scroll down to the Match Details panel to see each match listed with its start position, end position, and length. If your pattern includes capturing groups (parentheses), each group's captured value is shown as a badge. Named groups (e.g. `(?<year>\d{4})`) display their name alongside their value. Click any match to highlight it in the test string view.

4

Try Substitute or Validate Mode

Switch to Substitute mode using the tabs at the top to preview a find-and-replace result — enter a replacement string with backreferences like `$1` or `$&`. Or switch to Validate mode to paste a list of strings and instantly see which ones match your pattern. Use the Quick Reference cheatsheet on the right and click any Common Pattern to load it instantly.

Frequently Asked Questions

Why is my regex matching more (or less) than I expect?

The most common cause of unexpected matches is forgetting to anchor the pattern. Without `^` and `$`, a pattern like `\d+` matches any sequence of digits anywhere in the string — including inside longer words or numbers. Add `^\d+$` to require the entire string to be digits. Similarly, quantifiers like `.*` are greedy and will consume as much text as possible, potentially matching across content you intended to skip. Try the lazy variant `.*?` to make the quantifier stop at the earliest possible position. The flag toggles are another common culprit — enabling the `g` flag changes behavior from 'find first' to 'find all', and enabling `i` makes case irrelevant.

What do the capturing groups $1, $2 mean in replacement?

When your pattern contains parentheses like `(\w+)`, everything matched by that group is captured and made available in the replacement string as `$1` for the first group, `$2` for the second, and so on. For example, the pattern `(\w+)\s(\w+)` matching 'John Smith' can be replaced with `$2, $1` to produce 'Smith, John'. Named groups like `(?<first>\w+)` are referenced as `$<first>`. `$&` refers to the entire matched substring, `$`` to the text before the match, and `$'` to the text after. These backreferences only work in Substitute mode. If you reference a group number that doesn't exist in your pattern, the literal text `$1` (or whichever number) appears in the output.

Why does my pattern work differently on regex101 or Python?

Different programming languages and tools use different regex 'flavors' — slightly different implementations of the regular expression standard. This tester uses the JavaScript ECMAScript flavor, which differs from PCRE (used by PHP, Ruby, Perl, and regex101's default), Python's `re` module, and .NET. Key differences include: JavaScript requires the `u` flag to use Unicode property escapes like `\p{L}`; PCRE supports possessive quantifiers (`++`, `*+`) and atomic groups `(?>...)` which JavaScript does not; Python does not support lookbehinds of variable length; and JavaScript's multiline `m` flag only affects `^` and `$`, not `.`. If you need cross-language compatibility, stick to the common subset: basic character classes, quantifiers, non-capturing groups, and standard lookaheads.

What is catastrophic backtracking and how do I avoid it?

Catastrophic backtracking occurs when a regex engine must explore an exponential number of possible ways to match a pattern before concluding there is no match. The classic example is `(a+)+b` applied to a string of `a` characters with no `b` — the engine tries every possible grouping of the `a` characters, causing exponential slowdown. To avoid it: prefer possessive or atomic quantifiers when possible (not available in JavaScript), restructure nested quantifiers so they cannot match the same input in multiple ways, use specific character classes instead of `.*` where possible, and test your pattern against a worst-case non-matching input before deploying it in production. Patterns used on user-supplied input should always be validated for ReDoS (regex denial of service) vulnerabilities.

How does Validate mode differ from Match mode?

Match mode runs the regex against a single multi-line test string and shows all matches within it, with character positions and group values. It is ideal for exploratory testing — seeing exactly where and how your pattern matches inside a document. Validate mode takes a newline-separated list of values and tests each one independently, showing a pass (match) or fail (no match) indicator for each entry. Validate mode is specifically designed for checking whether a validation regex correctly accepts or rejects a set of inputs — for example, verifying that your email regex accepts 20 valid addresses and rejects 10 invalid ones before you deploy it in a form. The distinction is 'find matches inside text' (Match mode) versus 'does this exact value match?' (Validate mode).

Can I use this tool for non-JavaScript regex (Python, PCRE, etc.)?

This tester runs the JavaScript ECMAScript regex engine, so the results are accurate for JavaScript code. For most common patterns — basic character classes, quantifiers, capturing groups, lookaheads — the syntax is identical or very similar across flavors, so the tester is a useful first step even if you are ultimately targeting Python or PHP. Where the flavors diverge: JavaScript does not support possessive quantifiers, inline modifiers, or variable-length lookbehinds (added in Chrome 62+ but not all environments); Python uses `re.VERBOSE` for the `x` flag (not available in JS); PCRE supports `(?>...)` atomic groups. For production use in a non-JavaScript environment, verify critical patterns in the target language's interpreter. A future version of this tool may support multi-engine testing.

EverydayToolsSIMPLES • GRÁTIS • RÁPIDO

Ferramentas online gratuitas para profissionais não de TI. Calculadoras, conversores, geradores e mais.

Categorias Populares

  • Calculadoras de Saúde
  • Calculadoras Financeiras
  • Ferramentas de Conversão
  • Calculadoras de Matemática

Empresa

  • Sobre
  • Contato
  • Política de Privacidade
  • Termos de Serviço

© 2026 EverydayTools.io. Todos os direitos reservados.