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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Percent Expression
Expression
^\s*(\d{0,2})(\.?(\d*))?\s*\%?\s*$
Description
Basically this matches into variables for percentages.. It allows as much whitespace before and after the expression. $1 = Percent before decimal, $2 = percentage after decimal inc decimal, $3 = percentage after decimal. Disallowed anything past 99.99999 repeating percent. No negative percents either. Easy to implement but I do not need it.
Matches
10.5%, 1%, 1, .5, .0555%
Non-Matches
100%, -1%, -1, 200, 200.1
Author Rating: Not yet rated. Mike Willbanks
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: Better variant
Name: Nikolay Sonin
Date: 4/10/2009 4:43:49 PM
Comment:
^\s*((-){0,1}(\d{0,})(\.?(\d*)))?\s*\%?\s*$ This variant can also work with negative and big (> 100) percents


Title: Percent Expression issues
Name: Daniel
Date: 9/12/2006 4:13:16 PM
Comment:
It looks good at first but there are a few big holes in this one. These entries are allowed: 56323, %. Aside from that the unlimited whitespace between the number and the percent sign seems unnecessary and it would be nice to allow any percentile including 100% exactly.


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