What’s the notation for any number in re?
Like if I’m searching a string for any number, positive or negative.
I’ve been using \d+ but that can’t find 0 or -1
What’s the notation for any number in re? Like if I’m searching a string
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Searching for positive, negative, and/or decimals, you could use
[+-]?\d+(?:\.\d+)?This isn’t very smart about leading/trailing zeros, of course:
Edit: Corrected the above regex to find single-digit numbers.
If you wanted to add support for exponential form, try
[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?: