re.error: Nothing to Repeat

re.error: nothing to repeat at position 0

Quick Answer

You have a quantifier (*, +, ?) at the start of a pattern or after another quantifier. Quantifiers must follow a character or group to repeat.

Why This Happens

Regex quantifiers modify the preceding element. If there is no preceding element, the engine cannot determine what to repeat. Escape the quantifier to match the literal character.

The Problem

import re
result = re.search(r'*hello', text)

The Fix

import re
result = re.search(r'.*hello', text)  # .* matches anything before
# Or literal: re.search(r'\*hello', text)

Step-by-Step Fix

  1. 1

    Fix the pattern

    Ensure quantifiers come after a character, group, or character class.

  2. 2

    Escape literal quantifiers

    Use \* for literal asterisk, \+ for plus.

  3. 3

    Test your regex

    Use regex101.com to debug patterns.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free