KT。
Korelyy Toolskorelyy.com

Sign In / Sign Up

Welcome back — sign in to sync your favorites

Don't have an account?

By continuing you agree to our Terms and Privacy Policy

About Us

Meet the Korelyy team & mission

Privacy Policy

Our privacy commitment

Data Processing & Disclaimer

Data rules & disclaimer

Cookie Settings

Manage cookie preferences

Advertising & Support

Contact Us

Compliance

Tool verification

Blog

Tutorials, SEO guides & use cases

2026 Korelyy. All rights reserved.

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

My Profile

Manage your account info and preferences

?
-Free
-

Basic Info

-
Email & Password
Free
-

Security

This email was registered with a different method
← Back to all posts
PerformanceJavaScriptBenchmark

Regex vs. String.indexOf / .includes: When Is Regex 10× Slower? (2026 JS Benchmark)

We benchmarked 12 real-world string-matching scenarios across Chrome 126, Node 22, Bun 1.1 and Safari 18. Clear cut-off rules: when to use String methods (90% of cases) vs. when to reach for regex, plus 3 regex anti-patterns that cause 100× slowdowns.

K
By Korelyy Team
July 1, 2026·9 min Read

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: Frequently Asked Questions

Is regex always slower?

No. Simple regex can be faster than complex string operations. Only 10x slower for simple substring checks — use .includes() for those.

When to use regex vs string methods?

Use .includes()/.indexOf() for simple checks. Use regex for pattern matching with wildcards, character classes, or quantifiers.

How to optimize regex?

Avoid greedy quantifiers, use anchors to limit scope, compile once with RegExp constructor for repeated use.

Put the tutorial patterns to work instantly

Regex Tester
→
Try 100+ ready templates in Korelyy Toolbox →
☕ Support KorelyyIf this tool helped you, buy me a coffee

Contents

  • 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: Frequently Asked Questions