Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regular Expression To Find Number > 5,000

Posted on 2011-03-18
10
Medium Priority
?
691 Views
Last Modified: 2012-05-11
Hi folks, I am learning expressions and am looking for a way to search for any number that is greater than 5,000.

When used it could find a number like 5093 or 5093.53 ect basically anything greater than 5,000. Can you help me out a little. Explaination is good, not just solution, trying to learn not just copy. :)

0
Comment
Question by:CCSNV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35168828

5\d{3}(?:\.\d+)?

Explanation:
=============================================================
5             Literal
\d{3}         3 digits
(?: ... )?    Non-capturing group with a zero-or-one modifier (applied to entire group)
\.            Literal period
\d+           One-or-more digits

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35168837
Correction:
\d*5\d{3}(?:\.\d+)?

Explanation:
=======================================================================================
\d*           Zero-or-more digits (should capture numbers with 5 or more digits
5             Literal
\d{3}         3 digits
(?: ... )?    Non-capturing group with a zero-or-one modifier (applied to entire group)
\.            Literal period
\d+           One-or-more digits

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35168863
P.S.

The above does NOT take into account commas (grouping separators), so 5,000 would not be found.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:CCSNV
ID: 35168908
So not having to worry about commas or decimals is ok for example i can search 5,001.02 by typing in 500102. I tried it and it works.

Not quite understanding the  
\d{3}         3 digits

Open in new window


Can you help explain this better for me?

thanks
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35168965
In some regex engines, "\d" is shorthand for the character class "[0-9]", which means any character that is 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9--basically, any digit. The construct "{...}" is a quantifier, much the same way that * and + are. It has 4 forms:

{n} -- exactly n occurrences
{n,m} -- between n and m occurrences, inclusive
{n,} -- between n and infinity occurrences, inclusive ({1,} is the same as +)
{,m} -- between 0 and m occurrences, inclusive (the same as *)

Before we go further, perhaps I should clarify one thing:  are we speaking in terms of a specific language, or are you talking about regular expressions as it pertains to theory? There are some differences between the two.
0
 

Author Comment

by:CCSNV
ID: 35169067
as it pertains in theory. so i have eliminated the .NN so now i am just searching for items that are 5000 and larger so 5000 is written as 500000 no comma no decimal but need the range to be anything greater than 500000(5,000).

so if I had 5000.31 in my tables it is listed as 500031.  So to do this I should be able to use:

 
\d*6\d{3}(?:\d+)?

Open in new window


correct?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35169422
I need to correct one thing in my original post. The original post will find values that have a 5 in the fourth position from the right. It will not find what you asked for originally.

We can of course correct that. Following should find any value greater than 5000, and I've added the modification you mention in your last post. I am also providing and updated explanation.
\d{7,}|[5-9]\d{5}

Explanation:
=================================================================================================
\d{7,}       Five-or-more ( {5,} ) digits ( \d )        | This will handle numbers 10,000 and up
|            OR
[5-9]        Any single digit that is 5, 6, 7, 8, or 9  | This will handle numbers
\d{5}        Exactly Three ( {3} ) digits ( \d )        | 5,000 - 9,999

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35169424
My apologies for the incorrectness of my first post.
0
 

Author Comment

by:CCSNV
ID: 35169458
no worries thank you for the assistance. I am now starting to understand. Sometimes reading "dictionary" explaination are confusing but you have broke it down down for me in what I was looking for.

Thanks again for the assistance.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35169467
I found the following site when I was first learning regex:  www.regular-expressions.info . I think it is very well put together. There are of course numerous sites which cover regex, but that is the one I have experience with  = )
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question