Chuleta de regex
NUEVOChuleta de expresiones regulares con anclas, clases, cuantificadores, grupos, lookaround, flags y patrones listos, con notas de JavaScript. Con buscador y copia con un clic. La sintaxis se muestra en inglés.
Funciona al 100 % en tu navegador — lo que introduces nunca se sube ni se guarda en nuestros servidores.
79 entradas en 9 secciones
Anchors & boundaries
^Start of the string (start of each line with the m flag).
$End of the string (end of each line with the m flag).
\bWord boundary: between a word character and a non-word character.
\BNot a word boundary.
\AStart of the whole string. Not in JavaScript; use ^ without the m flag.
\zEnd of the whole string. Not in JavaScript; use $ without the m flag.
Character classes
.Any character except a line break (with the s flag, including line breaks).
\dA digit, same as [0-9] in most flavors.
\DAny character that is not a digit.
\wA word character: letter, digit or underscore (ASCII only in JavaScript).
\WAny character that is not a word character.
\sWhitespace: space, tab, line break and similar.
\SAny character that is not whitespace.
[abc]One of the listed characters: a, b or c.
[^abc]Any character except a, b and c.
[a-z]One character in a range, here lowercase a to z.
[a-zA-Z0-9]Several ranges in one class: ASCII letters and digits.
[\s\S]Any character including line breaks, a trick that works without the s flag.
Quantifiers
A quantifier applies to the item right before it.
*Zero or more times (greedy).
+One or more times (greedy).
?Zero or one time: makes the item optional.
{3}Exactly 3 times.
{2,}2 or more times.
{2,5}Between 2 and 5 times.
*?Lazy: zero or more times, as few as possible.
+?Lazy: one or more times, as few as possible.
{2,5}?Lazy range: as few repetitions as possible within 2 to 5.
a++Possessive quantifier: no backtracking. Supported in PCRE, Java and others, not in JavaScript.
Groups & backreferences
(abc)Capturing group: groups the pattern and remembers the match.
(?:abc)Non-capturing group: groups without remembering.
a|bAlternation: match a or b.
(cat|dog)s?Group an alternation, then make the "s" optional.
\1Backreference: the same text matched by capturing group 1.
(\w)\1Two identical word characters in a row, such as "ll".
(?<year>\d{4})Named capturing group (JavaScript, .NET, PCRE).
\k<year>Backreference to a named group in JavaScript.
(?P<year>\d{4})Named group syntax used by Python (and PCRE).
Lookaround
Lookarounds check the surroundings without including them in the match.
a(?=b)Positive lookahead: "a" only when followed by "b".
a(?!b)Negative lookahead: "a" only when not followed by "b".
(?<=\$)\d+Positive lookbehind: digits that come right after a $ sign.
(?<!\$)\b\d+Negative lookbehind: digits not preceded by a $ sign.
^(?=.*\d)(?=.*[a-z]).{8,}$Password-style check: at least 8 characters with a digit and a lowercase letter.
Flags
Written after the closing slash in JavaScript, e.g. /abc/gi.
gGlobal: find all matches instead of stopping at the first.
iIgnore case.
mMultiline: ^ and $ match at each line.
sDot-all: . also matches line breaks.
uUnicode: treat the pattern as code points and enable \p{...}.
ySticky (JavaScript): match only at lastIndex.
dIndices (JavaScript): add start and end positions of each group to the result.
(?i)Inline flag at the start of a pattern, used in Python, PCRE and Java. JavaScript does not support it.
Escapes & special characters
These characters have a special meaning and need a backslash to match literally: \ ^ $ . | ? * + ( ) [ ] { }
\.A literal dot.
\\A literal backslash.
\/A literal slash (needed inside /.../ literals in JavaScript).
\nLine feed (new line).
\rCarriage return.
\tTab.
\x41A character by its two-digit hex code, here "A".
\u00e9A character by its four-digit Unicode code, here "é".
\p{L}Any Unicode letter (needs the u flag in JavaScript).
\p{Lu}Any uppercase Unicode letter (needs the u flag in JavaScript).
Common patterns
Starting points, not full validators. Always test with your own data.
^[^\s@]+@[^\s@]+\.[^\s@]+$Email, loose check: [email protected]. The full email standard is far wider, so confirm by sending a message.
https?:\/\/[^\s/$.?#].[^\s]*Web URL with http or https, simple version. Misses other schemes and some valid edge cases.
^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$IPv4 address with each part from 0 to 255. Does not say whether the address is reachable.
^\d{4}-\d{2}-\d{2}$Date shaped like 2026-11-23. Checks the layout only, so 2026-99-99 also passes.
^([01]\d|2[0-3]):[0-5]\d$Time in 24-hour HH:MM format.
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$Hex color such as #fff or #1a2b3c, with optional #.
^[a-z0-9]+(?:-[a-z0-9]+)*$URL slug: lowercase words joined by single hyphens.
^\+?[0-9\s().-]{7,15}$Loose phone number check. Phone formats differ by country, so treat it as a rough filter.
^\s+|\s+$Leading and trailing whitespace, handy for trimming with a replace.
\s{2,}Two or more whitespace characters in a row, to collapse into a single space.
JavaScript notes
/pattern/flagsRegex literal syntax. Same as new RegExp("pattern", "flags").
regex.test(str)Returns true or false. With g or y, it moves lastIndex between calls.
str.match(regex)First match with groups, or all matches as an array when g is set.
str.matchAll(/(\d+)/g)Iterator of every match including groups. The regex must have the g flag.
str.replace(/(\w+) (\w+)/, "$2 $1")Replace using $1, $2 for capture groups, here swapping two words.
str.replaceAll(/a/g, "b")Replace every match. A regex argument must have the g flag.
const { groups } = /(?<y>\d{4})-(?<m>\d{2})/.exec(str)Read named groups from the groups object: groups.y and groups.m.
str.replace(re, "$<y>")Use a named group in a replacement string.
new RegExp(escapedText, "g")Build a pattern from a string. Escape user text first, since it may contain special characters.
Ejemplos rápidos
Entradas típicas y los resultados que produce esta herramienta.
Descripción general
Las expresiones regulares describen patrones de texto con una sintaxis compacta que es fácil de olvidar. Esta chuleta de regex cubre anclas, clases de caracteres, cuantificadores, grupos y referencias hacia atrás, lookaround, flags y escapes, además de patrones de partida para correo electrónico, URL, dirección IPv4, fecha y hora.
La sintaxis varía un poco entre implementaciones, así que las entradas indican dónde JavaScript, Python o PCRE se comportan de forma distinta, y una sección de JavaScript cubre los grupos con nombre, matchAll y los flags sticky y unicode. Los patrones habituales son puntos de partida con sus limitaciones, no validadores completos.
La sintaxis, los patrones y sus descripciones breves se muestran en inglés; solo la interfaz y el texto de la página están traducidos. Filtra la lista, copia un patrón y pruébalo con tu propio texto en el Probador de expresiones regulares. Todo se queda en tu navegador.
¿Por qué usar esta herramienta?
- Consulta la sintaxis de regex sin salir de la página
- Notas sobre las diferencias entre JavaScript y Python
- Patrones habituales con sus limitaciones
- Filtra por símbolo o palabra clave
- Copia cualquier patrón con un clic
Funciones
Anclas y clases
Límites, dígitos, caracteres de palabra, rangos y conjuntos negados.
Cuantificadores
Repetición voraz, perezosa y posesiva, con las implementaciones que admiten cada una.
Lookaround
Ejemplos de lookahead y lookbehind, incluida una comprobación al estilo de las contraseñas.
Patrones habituales
Correo, URL, IPv4, fecha, hora, color hexadecimal y slug, cada uno con su salvedad.
Notas de JavaScript
test, match, matchAll, replaceAll y grupos con nombre en código.
Copia por patrón
Cada fila tiene un botón Copiar con el texto exacto.
Cómo se usa
Elige una sección
Desplázate hasta Quantifiers, Lookaround, Flags u otro grupo (los títulos de sección están en inglés).
O filtra
Escribe un símbolo o una palabra como «lazy» o «email» en el cuadro de filtro.
Lee la nota
Revisa la descripción, en inglés, para ver las diferencias entre implementaciones antes de copiar.
Pruébalo
Pulsa Copiar y pega el patrón en el Probador de expresiones regulares con tu propio texto.