“Nothing to repeat” from Python regex

You do not need the * in the pattern, it causes the issue because you are trying to quantify the beginning of the pattern, but there is nothing, an empty string, to quantify.

The same “Nothing to repeat” error occurs when you

  • Place any quantifier (+, ?, *, {2}, {4,5}, etc.) at the start of the pattern (e.g. re.compile(r'?'))
  • Add any quantifier right after ^ / \A start of string anchor (e.g. re.compile(r'^*'))
  • Add any quantifier right after $ / \Z end of string anchor (e.g. re.compile(r'$*'))
  • Add any quantifier after a word boundary (e.g.re.compile(r'\b*\d{5}'))

Note, however, that in Python re, you may quantify any lookaround, e.g. (?<!\d)*abc and (?<=\d)?abc will yield the same matches since the lookarounds are optional.

Use

([a-zA-Z]+)\.csv

Or to match the whole string:

.*([a-zA-Z]+)\.csv

See demo

The reason is that * is unescaped and is thus treated as a quantifier. It is applied to the preceding subpattern in the regex. Here, it is used in the beginning of a pattern, and thus cannot quantify nothing. Thus, nothing to repeat is thrown.

If it “works” in VIM, it is just because VIM regex engine ignores this subpattern (same as Java does with unescaped [ and ] inside a character class like [([)]]).

Leave a Comment