Referencia completa de expresiones regulares con sintaxis, flags, grupos, lookaheads y ejemplos de patrones del mundo real.
Probar en el Tester de Regex →| Sintaxis | Descripción |
|---|---|
. | Any character except newline |
\d | Digit [0-9] |
\D | Non-digit [^0-9] |
\w | Word char [a-zA-Z0-9_] |
\W | Non-word character |
\s | Whitespace (space, tab, newline) |
\S | Non-whitespace |
[abc] | One of a, b, or c |
[^abc] | Not a, b, or c |
[a-z] | Character in range a–z |
[a-zA-Z] | Letter (any case) |
\p{L} | Any Unicode letter (u flag) |
| Sintaxis | Descripción |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary |
\B | Non-word boundary |
\A | Start of string (Python/Java) |
\Z | End of string (Python/Java) |
| Sintaxis | Descripción |
|---|---|
* | 0 or more (greedy) |
+ | 1 or more (greedy) |
? | 0 or 1 (optional) |
{n} | Exactly n times |
{n,} | n or more times |
{n,m} | Between n and m times |
*? | 0 or more (lazy) |
+? | 1 or more (lazy) |
?? | 0 or 1 (lazy) |
| Sintaxis | Descripción |
|---|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
\1 | Backreference to group 1 |
\k<name> | Named backreference |
(?|...) | Branch reset group (PCRE) |
| Sintaxis | Descripción |
|---|---|
(?=abc) | Positive lookahead — must be followed by abc |
(?!abc) | Negative lookahead — must NOT be followed by abc |
(?<=abc) | Positive lookbehind — must be preceded by abc |
(?<!abc) | Negative lookbehind — must NOT be preceded by abc |
| Bandera | Nombre | Descripción |
|---|---|---|
g | Global | Find all matches, not just the first |
i | Case-insensitive | Match regardless of case (A = a) |
m | Multiline | ^ and $ match start/end of each line |
s | Dotall | . matches newline characters too |
u | Unicode | Enable full Unicode support (\p{} classes) |
y | Sticky | Match only at lastIndex position (JS) |
x | Extended | Allow whitespace + comments in pattern (Python/PHP) |
| Patrón | Regex | Prueba |
|---|---|---|
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} | Probar en el Tester de Regex → | |
| URL | https?:\/\/[\w\-]+(\.[\w\-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=%]* | Probar en el Tester de Regex → |
| IPv4 Address | \b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b | Probar en el Tester de Regex → |
| Phone (US) | \+?1?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} | Probar en el Tester de Regex → |
| Date (YYYY-MM-DD) | \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) | Probar en el Tester de Regex → |
| Time (HH:MM) | (?:[01]\d|2[0-3]):[0-5]\d | Probar en el Tester de Regex → |
| UUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} | Probar en el Tester de Regex → |
| Hex Color | #(?:[0-9a-fA-F]{3}){1,2}\b | Probar en el Tester de Regex → |
| Slug | [a-z0-9]+(?:-[a-z0-9]+)* | Probar en el Tester de Regex → |
| ZIP Code (US) | \d{5}(?:-\d{4})? | Probar en el Tester de Regex → |
| Credit Card | (?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}) | Probar en el Tester de Regex → |
| HTML Tag | <([a-zA-Z][a-zA-Z0-9]*)(?:\s[^>]*)?\/?>.*?<\/\1> | Probar en el Tester de Regex → |
| Markdown Bold | \*\*([^*]+)\*\* | Probar en el Tester de Regex → |
| JWT Token | [A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+ | Probar en el Tester de Regex → |
| Semver | \bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?\b | Probar en el Tester de Regex → |
| GitHub Username | (?<=github\.com\/)([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,37}[a-zA-Z0-9])?) | Probar en el Tester de Regex → |
| Positive Integer | ^[1-9]\d*$ | Probar en el Tester de Regex → |
| Float / Decimal | -?\d+(?:\.\d+)? | Probar en el Tester de Regex → |
| Blank Lines | ^\s*$ | Probar en el Tester de Regex → |
| Duplicate Words | \b(\w+)\s+\1\b | Probar en el Tester de Regex → |
Una expresión regular es una secuencia de caracteres que define un patrón de búsqueda. Se usa para búsqueda, coincidencia y manipulación de cadenas. Regex está soportado nativamente en JavaScript, Python, Java, PHP, Go y la mayoría de los lenguajes de programación modernos.
Los cuantificadores codiciosos (*, +, {n,m}) coinciden con tantos caracteres como sea posible. Los cuantificadores perezosos (*?, +?, {n,m}?) coinciden con tan pocos caracteres como sea posible.
Los lookaheads (?=...) y lookbehinds (?<=...) son aserciones de ancho cero — verifican un patrón sin consumir caracteres. El lookahead positivo (?=foo) afirma que 'foo' sigue. El lookahead negativo (?!foo) afirma que 'foo' NO sigue.
La sintaxis central (clases de caracteres, cuantificadores, anclas) es consistente en la mayoría de los lenguajes. Sin embargo, características como lookbehind, grupos nombrados y flags específicos varían según el motor.