RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Real Float Number
Expression
[+-]?+(?>\d++\.?+\d*+|\d*+\.?+\d++)
Description
This regex is designed to fail fast (using possessive quantifiers) while still matching a floating decimal number all the time. Won't match scientific notation or fractions. Can be combined with other patterns. Note: This site's tester does not support them. If your language does not support possessive quantifiers try the following: (?>[+-]?)(?>(?>\d+)(?>\.?)(?>\d*)|(?>\d*)(?>\.?)(?>\d+))
Matches
+7 | -7.7 | .7 | 7. | etc
Non-Matches
1/7 | 7e10
Author Rating: The rating for this expression. Trinithis
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Real Float Number
Name: Rick S
Date: 8/1/2013 12:45:26 PM
Comment:
Thanks for this post. I was unclear how to speed this up so this was exactly what I was looking for. I don't think you need to look for digits preceding the decimal point in the second alternative because this case will be captured by the first alternative. Also if it gets to the second alternative then we should always see a decimal point. So the expression becomes. (?>[+-]?)(?>(?>\d+)(?>\.?)(?>\d*)|(?>\d*)(?>\.)(?>\d+))


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials