Probador Regex · Guía
Errores Comunes de Regex y Cómo Evitarlos
Un puñado de errores explica la mayoría de las expresiones regulares rotas. Reconocerlos ahorra horas de confusión.
Coincidencia codiciosa
Por defecto los cuantificadores son codiciosos: coinciden con todo lo posible. Un patrón como .*" puede tragarse mucho más de una sola cadena entrecomillada. Usa un cuantificador perezoso (.*?) o una clase negada ([^"]*) para coincidir con el mínimo en su lugar.
Caracteres especiales sin escapar
Caracteres como . ( ) [ ] + * ? tienen un significado especial. Para coincidir con ellos literalmente, escápalos con una barra invertida. Olvidar escapar un punto es una fuente clásica de patrones que coinciden con demasiado.
Olvidar los flags
Sin el flag global solo obtienes la primera coincidencia; sin el de ignorar mayúsculas te pierdes las variantes en mayúsculas. Configura los flags deliberadamente y prueba con el probador para confirmar la cobertura.
Preguntas frecuentes
Why does my regex match part of an invalid string?
Most regex functions search for a matching substring. Anchor the pattern for the whole string or use the engine's full-match API, then test leading and trailing junk explicitly.
What is a greedy regex mistake?
A greedy quantifier consumes as much input as it can, so .* may cross the delimiter you intended to stop at. Prefer an explicit boundary such as [^"]*; a lazy quantifier helps but is not always sufficient.
Why does a regex work online but not in my code?
The programming-language string parser may consume a backslash before the regex engine sees it, or the tester may use another engine or flags. Use raw strings or regex literals where available and inspect the final pattern.
Why does JavaScript regex test return alternating results?
A regex with the global or sticky flag retains lastIndex. Repeated test() calls start at different positions; remove the flag for boolean validation or reset lastIndex before each independent test.
What causes catastrophic regex backtracking?
Nested or overlapping repetitions give a backtracking engine too many ways to partition nearly matching input. Simplify ambiguous groups, bound input and repetition, and test long strings that fail near the end.
Should I use regex to validate an email or HTML?
Use regex only for modest structural checks. Full email rules and HTML parsing contain grammar and semantic details better handled by dedicated parsers and confirmation workflows.
¿Listo para probarlo?
Abre la herramienta gratuita Probador Regex en el navegador y aplica lo que acabas de leer: sin registro y procesando localmente.
Abrir la herramienta Probador Regex