• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 755
  • Last Modified:

Regular Expression To Find Number > 5,000

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
CCSNV
Asked:
CCSNV
  • 7
  • 3
1 Solution
 
käµfm³d 👽Commented:

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
 
käµfm³d 👽Commented:
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
 
käµfm³d 👽Commented:
P.S.

The above does NOT take into account commas (grouping separators), so 5,000 would not be found.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CCSNVAuthor Commented:
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
 
käµfm³d 👽Commented:
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
 
CCSNVAuthor Commented:
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
 
käµfm³d 👽Commented:
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
 
käµfm³d 👽Commented:
My apologies for the incorrectness of my first post.
0
 
CCSNVAuthor Commented:
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
 
käµfm³d 👽Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now