0

Hey guys I am new to python regex. Since I am bad in regex i never spend more time in regex but i have a project now and i face some problems in my project.

When I run following piece of code

import re
line = "100, 1000 or 10000?";
num = re.sub(r'{3,4}', "", line)
print num

I get error like

File "/usr/local/lib/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat

Since am new to regex i don't know why am getting this. Hope you guys can help me.

1
  • 1
    What do you expect to be the output? The error comes from the fact that you told the regex to match something 3 to 4 times, but not what Commented May 27, 2014 at 9:05

1 Answer 1

3

{3,4} is a modifier; there needs to be something to modify. It basically means "from three to four of". What does "from three to four of" even mean?

\d is "a digit". \d{3,4} means "from three to four of a digit" (i.e. 3-4 digits).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.