?
Solved

Regular Expression To Find Number > 5,000

Posted on 2011-03-18
10
Medium Priority
?
646 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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
Course of the Month15 days, 15 hours left to enroll

743 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