Select numbers greater/less than?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Select numbers greater/less than?
This has to be simple, yet I can't find an answer anywhere. How do I find numbers greater than a given value? I can't simply search for >200, for example.
Thanks!
Thanks!
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
It isn't simple. Regular expressions can't count: all they know about is uninterpreted characters. But you can do this with a certain amount of effort. For the specific example you give, try
\<(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[0-9]{4,})\>
This assumes you are using "Posix" regular expression syntax:
\<(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[0-9]{4,})\>
This assumes you are using "Posix" regular expression syntax:
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
To expand on ben_joseph's answer, it may help to understand how the expression is put together:
20[1-9] matches 201 to 209 (20 followed by 1-9).
2[1-9][0-9] matches 210 to 299 (2 followed by 1-9, followed by 0-9).
[3-9][0-9]{2} matches 300 to 999 (3-9 followed by two occurrences of 0-9).
[0-9]{4,} matches 1000 and higher (4 or more occurrences of 0-9).
| means "or", ( and ) group the expression together, and \< and \> anchor the expression to the start and end of a word.
You can extrapolate this to construct an expression for other numbers.
20[1-9] matches 201 to 209 (20 followed by 1-9).
2[1-9][0-9] matches 210 to 299 (2 followed by 1-9, followed by 0-9).
[3-9][0-9]{2} matches 300 to 999 (3-9 followed by two occurrences of 0-9).
[0-9]{4,} matches 1000 and higher (4 or more occurrences of 0-9).
| means "or", ( and ) group the expression together, and \< and \> anchor the expression to the start and end of a word.
You can extrapolate this to construct an expression for other numbers.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
Quite right. But leading zeros usually don't have to be dealt with. If they do, use this instead of my previous suggestion:
\<0*(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[1-9][0-9]{3,})\>
Edit: corrected typo.
\<0*(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[1-9][0-9]{3,})\>
Edit: corrected typo.
Last edited by ben_josephs on Thu Oct 11, 2012 7:02 am, edited 1 time in total.
Solution updated for Numbers falling at the end of a line!
ben_josephs' solutions work fine EXCEPT when the numbers fall at the end of a line.
\< and \> anchor the expression to the start and end of a word but this FAILS at the end of a line.
Hence we need the following:
\<0*(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[1-9][0-9]{3,})($|\>)
to accommodate this possibility!
\< and \> anchor the expression to the start and end of a word but this FAILS at the end of a line.
Hence we need the following:
\<0*(20[1-9]|2[1-9][0-9]|[3-9][0-9]{2}|[1-9][0-9]{3,})($|\>)
to accommodate this possibility!
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm