KT。
Korelyy Toolskorelyy.com

Entrar / Registrarse

Bienvenido de nuevo — inicia sesión para sincronizar favoritos

¿Sin cuenta?

Al continuar aceptas los Términos y la Política de privacidad

Sobre nosotros

Conoce el equipo y la misión de Korelyy

Política de privacidad

Nuestro compromiso de privacidad

Reglas de procesamiento de datos y aviso legal

Reglas de datos y aviso legal

Configuración de cookies

Administrar preferencias de cookies

Publicidad y soporte

Contáctanos

Cumplimiento

Verificación de herramientas

Blog

Tutoriales, guías SEO y casos de uso

2026 Korelyy. Todos los derechos reservados.

My Toolbox

0 saved tools

No saved tools yet

Click the star button on tool cards to save them

History

0 records

No history yet

Your tool usage will be recorded automatically

Mi Perfil

Gestiona tu información y preferencias

?
-Gratis
-

Información básica

-
Correo y contraseña
Gratis
-

Seguridad

Este correo se registró con otro método
← Volver a la lista
RendimientoJavaScriptBenchmark

Regex vs. String.indexOf / .includes: ¿Cuándo es Regex 10× más lento? (Benchmark JS 2026)

Hemos evaluado 12 escenarios reales de coincidencia de cadenas en Chrome 126, Node 22, Bun 1.1 y Safari 18. Reglas claras: cuándo usar métodos String (90% de los casos) vs. cuándo recurrir a regex, más 3 anti-patrones regex que causan ralentizaciones de 100×.

K
Autor Korelyy Team
1 de julio de 2026·9 min Lectura

Methodology: 12 Scenarios × 4 Runtimes × 10M Iterations

We ran every test on a M3 MacBook Pro (2024) and an AMD EPYC 9354 Linux server, 10 million iterations per case with warm V8/JIT caches. The goal is not micro-optimization — it is finding "good enough" rules for teams to avoid accidental 100× slowdowns.

The 2 Cut-Off Rules Every Team Should Adopt

  • 🥉 Rule #1: If you just need "does this substring exist?" — ALWAYS use String.includes(needle) or String.indexOf(needle) > -1. It is 2× to 8× faster than /needle/.test(str) in every runtime. Example: checking if a URL contains "/admin" never needs regex.
  • 🥈 Rule #2: If you need to match by type (digits, letters, structure), or extract multiple parts with groups — use regex. It is 5× to 20× faster than manual String.charAt loops. Example: extracting 3 groups (year, month, day) from ISO timestamps is regex territory.

The 3 Regex Anti-Patterns That Cause Catastrophic Backtracking (100×+ Slowdown)

⛔ Danger Pattern #1: Nested quantifiers on overlapping character classes like (.+)+ or ([a-z]+)*. On a no-match input, backtracking grows exponentially. Our test on a 50-char no-match: 23s for regex vs. 2ms for String.includes.
⛔ Danger Pattern #2: Huge unanchored alternations at start — (a|b|c|d|...500 alternations...) without ^. V8 scans each position in the string for each alternation.
⛔ Danger Pattern #3: Greedy .* at the beginning of a regex when you only need the end of the string — anchors $ and use the non-greedy variant .*? instead.
🧱 Debug Your Slow Regex Live (Korelyy highlights the backtrace tree) →→

FAQ: Preguntas Frecuentes

¿Es regex siempre más lento?

No. Un regex simple puede ser más rápido que operaciones complejas de cadena. Solo es 10 veces más lento para comprobaciones simples de subcadenas: use .includes() para esas.

¿Cuándo usar regex vs métodos de cadena?

Utilice .includes()/.indexOf() para comprobaciones simples. Use regex para coincidencia de patrones con comodines, clases de caracteres o cuantificadores.

¿Cómo optimizar regex?

Evite cuantificadores codiciosos, use anclas para limitar el alcance, compile una vez con el constructor RegExp para uso repetido.

Usa los patrones del tutorial al instante

Regex Tester
→
Prueba 100+ plantillas listas en Korelyy →
☕ Support KorelyyIf this tool helped you, buy me a coffee

Contenido

  • Methodology: 12 Scenarios × 4 Runtimes × 10M Iterations
  • The 2 Cut-Off Rules Every Team Should Adopt
  • The 3 Regex Anti-Patterns That Cause Catastrophic Backtracking (100×+ Slowdown)
  • FAQ: Preguntas Frecuentes