Herramientas Guías
developer Gratis Sin registro

Probador y depurador de expresiones regulares

Pruebe expresiones regulares con resaltado de coincidencias en tiempo real, grupos de captura y modo de reemplazo.

Cargando la herramienta…

Acerca de esta herramienta

Herramienta interactiva de prueba de expresiones regulares. Ingrese un patrón y una cadena de prueba para ver todas las coincidencias resaltadas en tiempo real. Vea los grupos de captura, los grupos con nombre y las posiciones de las coincidencias. Cambie al modo Reemplazar para previsualizar las sustituciones. Admite todos los indicadores de expresiones regulares de JavaScript (g, i, m, s, u).

Cómo usar

  1. 1 Ingrese su expresión regular en el campo Patrón.
  2. 2 Opcionalmente, agregue indicadores (g para todas las coincidencias, i para no distinguir mayúsculas y minúsculas, m para multilínea).
  3. 3 Pegue su cadena de prueba — las coincidencias se resaltan en tiempo real.
  4. 4 Cambie a la pestaña Reemplazar para previsualizar sustituciones con $1, $2 o grupos con nombre.

What a regular expression actually does

A regular expression — a "regex" — is a tiny pattern language for describing the shape of text rather than its exact contents. Instead of searching for the literal word "color", you can write a pattern that matches "color" or "colour", any string of digits, every email-looking token, or each tag in a block of HTML. A regex engine reads your pattern left to right and tries to align it against the test string, one position at a time, backtracking when a branch fails. This tester uses JavaScript's built-in RegExp engine (the ECMAScript flavour), so anything that works here works the same way in Node.js and every modern browser. The pattern and your test text are evaluated entirely in your browser — nothing is uploaded.

The building blocks

Most patterns combine a small set of pieces:

PieceMeaningExample
\d \w \sA digit, word character, or whitespace\d\d matches "42"
[abc]Any one character in the set[aeiou] matches a vowel
+ * ?One-or-more, zero-or-more, optionala+ matches "aaa"
{2,4}Between 2 and 4 repetitions\d{3,4} matches "1234"
(…)A capture group you can extract(\d+)-(\d+)
|Alternation (either side)cat|dog

The two slashes shown on either side of the pattern field are the regex delimiters — you type only the pattern between them. The small box to the right holds the flags.

Flags, and one thing this tester does for you

Flags change how the whole pattern behaves. i makes matching case-insensitive, m makes ^ and $ anchor to each line instead of the whole string, s lets . match newlines, and u turns on full Unicode handling. The g (global) flag finds every match instead of stopping at the first. This tester always adds g for you internally, so the highlighter and match list show all occurrences even if you forget it — useful, but remember that in your own code, without g, only the first match is returned.

A worked example

Say you want to pull the year and month out of dates like 2026-06-09. Type the pattern (?<year>\d{4})-(?<month>\d{2}) and paste a paragraph containing several dates. As you type, the tester highlights each match in a rotating set of colours and shows a running count. The Match Details panel lists every match with its character index range, the exact matched value, the numbered capture groups ($1 = the year, $2 = the month), and the named groups (year and month) spelled out. Seeing the index range is what makes this a debugger rather than a search box: you can tell exactly where in the string each match landed and why two near-matches behaved differently.

Replace mode

Switch to the Replace tab to preview substitutions without changing your data. The replacement string supports the same back-references as JavaScript's String.replace: $1, $2 insert captured groups, $& inserts the whole match, and $<name> inserts a named group. For example, with pattern (\w+)@(\w+) and replacement $2 [at] $1, the text "ada@example" becomes "example [at] ada". The result updates live, so you can tune the pattern and the replacement together before pasting either into your editor or script.

Where regex earns its keep

Reach for a regex when the pattern is regular but the exact text varies. Common jobs include validating that a field looks like an email or phone number, extracting every URL or hashtag from a block of prose, splitting a log line into its timestamp and message, find-and-replacing across many variations at once, and stripping or reformatting markup. The test-and-replace workflow here mirrors those tasks: build the pattern in Test mode until the highlight covers exactly what you intend and nothing more, confirm the capture groups in the details panel, then move to Replace mode to shape the output. A useful discipline is to test against negative examples too — paste in strings that should not match and confirm the count stays at zero, since an over-eager pattern that matches too much is a more common bug than one that matches too little.

Common mistakes

  • Greedy quantifiers swallowing too much. .* matches as much as possible, so <.*> on <a><b> grabs the whole thing. Add a ? to make it lazy: <.*?> stops at the first >.
  • Forgetting to escape special characters. A literal dot, plus, or parenthesis must be escaped: write \. to match a real period, since a bare . matches almost any character.
  • Anchors without the right flag. ^ and $ match the start and end of the whole string by default; add the m flag if you mean the start and end of each line.
  • Assuming lookbehind everywhere. JavaScript supports lookbehind (?<=…), and so does this tester, but some other engines do not — check your target language before relying on it.
  • Catastrophic backtracking. Nested quantifiers like (a+)+ against a long non-matching string can hang the engine. Keep patterns specific and avoid overlapping repetition.

Preguntas frecuentes

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}