0

I'm new with python and regular expressions.

I have this regular expressions and i don't know what is the purpose of this

r'(\d+)\.(\d*)'

all I know is it matches a digit from 0 to 9.

can anyone help me explain it?

thanks..

1
  • 3
    Take a look at the docs. Commented May 20, 2012 at 14:47

3 Answers 3

2

It matches a string containing one or more decimal digits, followed by a decimal place, followed by 0 or more decimal digits - ie, a floating-point number. It returns the two strings of digits.

For example, if you try it on the string "123.456" it will return ("123", "456").

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

2 Comments

It's kind of strange though that although it allows numbers with zero decimals, the dot is required. I think r'(\d+)\.?(\d*)' would make more sense to catch floats.
(shrug) it matches python syntax; 0 is int, 0. is float.
1

This looks for at least one digit (or more) followed by a decimal point and zero or more digits after it.

This quick reference/cheat sheet might be helpful looking up the parts that make up regular expressions.

This is a very nice Google video tutorial on regular expressions.

Comments

0

http://docs.python.org/library/re.html read it up. It will definitely be more enlightening than any answer you get here. That though matches digits (1 or more) followed by a decimal point and some further numbers (0 or more)

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.