close

[Solved] regex error – nothing to repeat

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error regex error – nothing to repeat in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How regex error – nothing to repeat Error Occurs?

Today I get the following error regex error – nothing to repeat in python.

How To Solve regex error – nothing to repeat Error ?

  1. How To Solve regex error – nothing to repeat Error ?

    To Solve regex error – nothing to repeat Error regular expression normally uses * and + in theory of language. I encounter the same bug while executing the line code

  2. regex error – nothing to repeat

    To Solve regex error – nothing to repeat Error regular expression normally uses * and + in theory of language. I encounter the same bug while executing the line code

Solution 1

regular expression normally uses * and + in theory of language. I encounter the same bug while executing the line code

re.split("*",text)

to solve it, it needs to include \ before * and +

re.split("\*",text)

Solution 2

It seems to be a python bug (that works perfectly in vim). The source of the problem is the (\s*…)+ bit. Basically , you can’t do (\s*)+ which make sense , because you are trying to repeat something which can be null.

>>> re.compile(r"(\s*)+")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 180, in compile
    return _compile(pattern, flags)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 233, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

However (\s*\1) should not be null, but we know it only because we know what’s in \1. Apparently python doesn’t … that’s weird.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read