Regular expressions and text guides

Regex backtracking: spot unsafe patterns without freezing a page

Recognize ambiguous repetition and design bounded validation without benchmarking hostile inputs in the browser.

Nav Tools ·

Look for ambiguous repetition

Nested or overlapping repetition can let a backtracking engine explore many ways of partitioning the same input.

A near-match that fails at the end may be much slower than a successful example. A short valid fixture cannot prove runtime safety.

Ambiguous example: ^(a+)+$
Simpler equivalent for this language: ^a+$
Use only short inputs when inspecting the first pattern.

Simplify the accepted language

When nested repetition adds no actual grammar requirement, replace it with one repetition. For more complex formats, prefer a parser or a safe regex engine.

Anchor full-value validators and use specific character classes, but remember that anchors alone do not eliminate backtracking.

Enforce input and execution bounds

Bound input length before evaluating untrusted text. On a server, isolate evaluation or choose an engine with predictable complexity where possible.

Nav Tools runs Regex Tester in a Worker with a 1.5-second execution limit. That protects the page, not the regex in your backend.

Do not assume all regex tools share isolation

The site's find-and-replace tool has a different execution path from Regex Tester. Do not use it to stress-test suspicious expressions.

Review the pattern, measure controlled small cases in an isolated test environment, and include malformed near-matches in the production validation plan.

References

← Regular expressions and text guides