Herramientas Guías
developer Gratis Sin registro

Hoja de Referencia y Probador de Regex

Referencia interactiva de expresiones regulares con pruebas de patrones en vivo y resaltado de coincidencias.

Cargando la herramienta…

Acerca de esta herramienta

Explore una referencia regex completa y categorizada que cubre anclajes, clases de caracteres, cuantificadores, grupos y caracteres especiales — cada entrada incluye el símbolo, nombre, descripción y un ejemplo trabajado. Use el probador rápido en la parte superior para ingresar cualquier texto y patrón y ver las coincidencias resaltadas en tiempo real. La copia con un clic coloca cualquier patrón directamente en su portapapeles.

Cómo usar

  1. 1 Escriba o pegue su cadena de prueba en el área de texto en la parte superior.
  2. 2 Ingrese un patrón regex y elija las banderas (g, i, m, s) según sea necesario.
  3. 3 Las coincidencias se resaltan en vivo; el recuento de coincidencias se muestra debajo de la entrada.
  4. 4 Explore la tabla de referencia a continuación y haga clic en 'Copiar' en cualquier entrada para copiar ese patrón.

What a regular expression really is

A regular expression (regex) is a compact pattern that describes a set of strings. Instead of searching for one literal word, you describe its shape — "three digits," "a word at the start of a line," "anything between angle brackets" — and the engine finds every piece of text that fits. This page is two things at once: a categorised cheat sheet of the building blocks, and a live tester where you type a pattern and watch it highlight matches in your own text in real time. Learning regex by reading definitions is slow; learning it by seeing a pattern light up exactly what you expected is fast.

The five families of building blocks

Every regex is assembled from a small vocabulary. The cheat sheet groups them into five categories, each with a runnable example you can copy:

  • Anchors match positions, not characters: ^ (start), $ (end), and \b (word boundary). \bcat\b matches "cat" in "the cat sat" but not the "cat" inside "concatenate."
  • Character classes match one character from a set: \d (digit), \w (word character), \s (whitespace), [aeiou] (any listed character), [^...] (anything not listed), and . (any character except newline).
  • Quantifiers say how many: * (zero or more), + (one or more), ? (optional), and {2,4} (between two and four). Their lazy versions, like *?, match as few characters as possible.
  • Groups and lookarounds: (...) captures, (?:...) groups without capturing, and lookahead/lookbehind such as (?<=\$)\d+ match a position based on what surrounds it without consuming those characters.
  • Special characters: alternation | (or), plus escapes for newline \n, tab \t, and carriage return \r.

Greedy versus lazy: the classic trap

This is the single most common source of regex confusion. By default quantifiers are greedy — they grab as much as they can. Run <.*> against <b>bold</b> in the tester and it matches the entire string, from the first < to the last >, because .* swallowed everything in between. Add a single ? to make it lazy — <.*?> — and it now matches just <b>, then </b> separately, because the engine stops at the first > it can. Seeing both behaviours highlighted side by side makes the difference click instantly.

Flags change the rules

The tester exposes the four flags you toggle most:

FlagEffect
gGlobal — find all matches, not just the first (on by default here so the tester can highlight every hit).
iCase-insensitive — cat also matches "Cat" and "CAT".
mMultiline — ^ and $ match the start and end of each line, not just the whole string.
sDotall — . also matches newline characters.

A worked example: validating a price

Suppose you want every dollar amount in a sentence. Paste The shirt is $25 and the hat is $9 into the test string and type the pattern \$\d+. The \$ escapes the literal dollar sign (an unescaped $ would mean "end of string"), and \d+ grabs one or more digits after it. The tester highlights $25 and $9 and reports "2 matches." Want only the number, not the sign? Use a lookbehind: (?<=\$)\d+ matches the digits while leaving the $ out of the highlight.

Common mistakes the tester helps you catch

  • Forgetting to escape special characters. A literal dot, dollar, question mark, or parenthesis must be written \., \$, \?, \(. An unescaped one means something else entirely.
  • Greedy matches that overreach. If your pattern grabs far more than intended, reach for the lazy version first.
  • Assuming . matches everything. By default it skips newlines — add the s flag if your text spans multiple lines.
  • Invalid syntax. If your pattern won't compile, the tester shows the exact error message in red instead of silently failing, so you can fix the typo on the spot.

Privacy

The tester uses your browser's own built-in regex engine (the same one JavaScript uses), so every pattern and every test string is evaluated locally. Nothing you type — neither your patterns nor the text you test them against — is sent to or stored on any server.

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.) #}