⚡
usefultools.dev
.*

Chuleta de regex

NUEVO

Chuleta 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).

  • \b

    Word boundary: between a word character and a non-word character.

  • \B

    Not a word boundary.

  • \A

    Start of the whole string. Not in JavaScript; use ^ without the m flag.

  • \z

    End 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).

  • \d

    A digit, same as [0-9] in most flavors.

  • \D

    Any character that is not a digit.

  • \w

    A word character: letter, digit or underscore (ASCII only in JavaScript).

  • \W

    Any character that is not a word character.

  • \s

    Whitespace: space, tab, line break and similar.

  • \S

    Any 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|b

    Alternation: match a or b.

  • (cat|dog)s?

    Group an alternation, then make the "s" optional.

  • \1

    Backreference: the same text matched by capturing group 1.

  • (\w)\1

    Two 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.

  • g

    Global: find all matches instead of stopping at the first.

  • i

    Ignore case.

  • m

    Multiline: ^ and $ match at each line.

  • s

    Dot-all: . also matches line breaks.

  • u

    Unicode: treat the pattern as code points and enable \p{...}.

  • y

    Sticky (JavaScript): match only at lastIndex.

  • d

    Indices (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).

  • \n

    Line feed (new line).

  • \r

    Carriage return.

  • \t

    Tab.

  • \x41

    A character by its two-digit hex code, here "A".

  • \u00e9

    A 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/flags

    Regex 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.

Clase
Cualquier letra Unicode (flag u)
\p{L}
Lookbehind
Dígitos después de un signo $
(?<=\$)\d+
Patrón
Fecha con el formato 2026-11-23
^\d{4}-\d{2}-\d{2}$
Grupo
Grupo con nombre para un año
(?<year>\d{4})
📖

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

1

Elige una sección

Desplázate hasta Quantifiers, Lookaround, Flags u otro grupo (los títulos de sección están en inglés).

2

O filtra

Escribe un símbolo o una palabra como «lazy» o «email» en el cuadro de filtro.

3

Lee la nota

Revisa la descripción, en inglés, para ver las diferencias entre implementaciones antes de copiar.

4

Pruébalo

Pulsa Copiar y pega el patrón en el Probador de expresiones regulares con tu propio texto.

🤔

Preguntas frecuentes