Skip to content
86% off$349 $48.86code BF2026

Guides

regex101 timeout error: fix the a-zA-z range and backtracking

regex101 times out but Python's re works? Fix the a-zA-z and /-_ range typos, remove overlapping quantifiers, and know when raising the timeout is enough.

GuideUpdated 6 min read

On this page

You pasted a pattern into regex101, it showed a timeout error, and the same pattern in Python's re returned the result you expected. The pattern in the original report was:

text
url\(?['"][a-zA-z\/-_]+logo?[a-zA-z\/-_.]+['"]\)?

The reported advice was twofold: raise the timeout (the report put regex101's default at 2 seconds), and fix the character classes, which contain an A-z range and a /-_ range that match more than intended. We have not verified regex101's current default. The two points interact, so the order of fixes matters.

Why the timeout happens

Two separate problems sit in this pattern. They produce different symptoms, so it helps to tell them apart.

  1. Range typos (wrong matches, not slowness by themselves). They make each class accept far more characters than you meant, which gives the engine more ways to match and more paths to retry.
  2. Overlapping quantifiers (the usual cause of the timeout). A class with +, then the literal log, then o?, then a second class with +: both classes contain l, o and g. When a match fails, the engine tries every way of splitting the text between the first +, the literal and the second +.
  3. A long or near-matching input. Backtracking cost depends on the text. We can't see the original test string, so we can't say how much of the slowdown came from the pattern and how much from the input.
  4. Different engines, different optimizations. Python's re and a tester's engine for a given flavor can optimize differently, so one may finish while another gives up. This is a plausible explanation for the mismatch, not a confirmed one for this exact case.

The textbook "catastrophic backtracking" is a sharper shape: nested quantifiers such as (a+)+$ run against text that almost matches. If your real pattern has a quantified group inside another quantified group, fix that first.

Fix the ranges: a-zA-z and /-_

Inside [...], x-y is a range of character codes, not a list with a hyphen between. Two ranges in that pattern match far more than intended.

WrittenWhat it actually matches
A-zA to z in ASCII: letters plus [ \ ] ^ _ and the backtick
\/-_A range from / to _: /, digits, : ; < = > ? @, A-Z, and [ \ ] ^ _

The hyphen itself is not in the class, because it was consumed as the range operator. The author wanted letters, slash, hyphen and underscore. What they got accepts a lot of punctuation and never matches -.

You can check the A-z part in Python:

python
import re
print(re.findall(r"[A-z]", "Z[\\]^_`a"))
# ['Z', '[', '\\', ']', '^', '_', '`', 'a']

Python accepts these ranges without complaint, so the typo produces wrong matches instead of an error. That is why it goes unnoticed.

The fix is a capital Z, and the hyphen first or last in the class (or escaped as \-):

text
[a-zA-Z/_-]
[a-zA-Z/_.-]

The old class also matched digits and : by accident. If your input needs them (a url('https://…') value does), add 0-9 and : back on purpose.

Remove the overlapping quantifiers

Two ways to cut the work for the original pattern.

Option 1: one corrected class

This keeps the meaning and fixes the ranges:

text
url\(?['"][a-zA-Z0-9_/-]+logo?[a-zA-Z0-9_/.-]+['"]\)?

It is correct, but the two classes still overlap, so it is not necessarily fast.

Option 2: check for log once, then match

A lookahead checks for log inside the quoted text, and a single quantifier then consumes the string:

text
url\(?(?=['"][^'"]+log[^'"])['"][a-zA-Z0-9_/.-]+['"]\)?

The lookahead requires at least one character before log and one after it, like the original. Adjust the consuming class to what your URLs contain. Lookaheads work in ICU, PCRE and Python.

Decide what logo? means

As written, only the final o is optional, so it matches log or logo. If you meant the whole word logo, drop the ?.

Raise the timeout (last resort)

Raising the timeout only helps when the pattern is correct and merely slow. It does not fix the range typos, and it can hide a pattern that will also be slow in your real program. Check the tester's own settings or documentation for how its limit works today; we haven't verified it.

When you test on regex101, pick the Python flavor so you check the syntax re uses.

Quick reference: symptom to fix

SymptomLikely causeFix
Matches stray punctuationA-z rangeWrite A-Z
Never matches -Hyphen used as a range operatorPut - first or last, or escape it
Timeout on failing inputTwo classes with + around a literalLookahead plus one quantifier
Timeout on (x+)+ shapesNested quantifiersRewrite so each character matches one way
Fast on match, slow on non-matchUnanchored scanAnchor with ^ or \b

Test the lookahead version in Bytepliers

Bytepliers can't fix the pattern for you, and it has no setting to raise its live timeout. It does give you a quick check on macOS 14 Sonoma or later. We make it, so weigh this part accordingly; if regex101 and Python already cover what you need, you don't need another app.

  1. Open Regex Tester (⌘8).
  2. Paste the Option 2 pattern into the pattern field.
  3. Paste two lines into Test String: url('/img/logo.png') and url('/img/banner.png').
  4. Check the highlights: the first line should match, the second should not, because it has no log.
  5. Replace the test string with a long run of letters that never closes the quote (a few thousand characters). If the timeout message appears, the pattern still overlaps somewhere. Shorten the input until it clears, then grow it again.
  6. To run a slower pattern, use Insert into Pipeline. It adds a Regex Extract, Replace or List step with your flags and opens Pipelines, where regex steps are allowed 2 seconds.

What to expect:

  • Live evaluation stops after 250 ms and shows "Timed out after 250 ms — likely catastrophic backtracking". A pattern that passes at that limit is unlikely to be slow on ordinary input, though that is a rule of thumb, not a guarantee.
  • The engine is ICU (NSRegularExpression syntax), not Python's re. The class fixes and lookahead above use syntax both support, but test with your own strings before trusting the result in Python.

Checklist before you try again

  • Every x-y range in brackets means what you intend (A-Z, not A-z).
  • Hyphens inside classes are first, last or escaped.
  • No two adjacent quantified classes can match the same characters.
  • No quantified group inside another quantified group.
  • The pattern is anchored where the match must start.
  • You tested with a short input first, then a long one.

If nothing works

If the pattern is correct and still times out, the cause may be the input or the tester. For regex101, use the contact route on its own site. For a problem inside Bytepliers, contact us through MacSuite support. Include the pattern, a shortened test string that still reproduces it, the flavor or engine, the exact message, and the timing you saw.

text
Regex Tester shows "Timed out after 250 ms — likely catastrophic backtracking".
Pattern: url\(?(?=['"][^'"]+log[^'"])['"][a-zA-Z0-9_/.-]+['"]\)?
Input: a 5,000-character string (attached) that ends without a closing quote.
macOS version: (add yours). Bytepliers version: (add yours).
I already fixed the A-z range and removed the overlapping classes.
Is there a way to run this pattern with a longer limit?

Common questions

Why does [a-zA-z] not raise an error?

Because A-z is a valid range of character codes. The engine has no way to know you meant Z.

Is [a-zA-Z/_-] the same as [\w/-]?

Not quite. \w also matches digits and, in many engines, non-ASCII letters. Use it only if that is what you want.

Should I just raise the timeout and move on?

Only after the ranges are fixed and the quantifiers no longer overlap. Otherwise you are hiding a slow pattern.

Can I raise the live timeout in Bytepliers?

No. The live limit is 250 ms. Insert into Pipeline runs the pattern as a pipeline step with a 2-second limit instead.

Every app.
One purchase.