Regex: Search for numbers

General discussion related to "Everything".
Post Reply
Debugger
Posts: 630
Joined: Thu Jan 26, 2017 11:56 am

Regex: Search for numbers

Post by Debugger »

For me, this regular expression is incorrect:
^([0]?[1-9])$
^(0?[1-9])$

0? optionally match a zero
[1-9] match one of the characters between 1 and 9


I want the match to be from 01 to 09 -or- 01 to 80


EDIT:

Regex Engine

PCRE: not work
^[0]{1}?[1-9]$

Boost.Regex: work
^[0]{1}?[1-9]$
RegexNinja
Posts: 18
Joined: Sat Apr 11, 2020 2:45 pm

Re: Regex: Matching number ranges

Post by RegexNinja »

Hi.. Here's two ways to PCRE-match: Any2Digits from 01-80

Alternates:
^([0][1-9]|[1-7][0-9]|80)$
.. 01-09.. |..10-79.. |80

NegatedLookArounds:
^(?!00)([0-8][0-9])(?<!8[1-9])$
Not00->(00 thru 89)<-Not 81-89

Without regex enabled, both examples need quoting because of the | < ! characters:
regex:"^([0][1-9]|[1-7][0-9]|80)$"
regex:"^(?!00)([0-8][0-9])(?<!8[1-9])$"

Hope it helps.. Cheers!
therube
Posts: 5060
Joined: Thu Sep 03, 2009 6:48 pm

Re: Regex: Search for numbers

Post by therube »

Without regex enabled, both examples need quoting because of the | < ! characters
Ah, that is important.

I didn't read down far enough & tried & tried but couldn't get it to work.
So I split it up, which was fine as far as it goes,
regex:^[0][1-9]$|regex:^[1-7][0-9]$|regex:^80$


Then I was like, if mine works, what was I doing wrong with your example?

I was using regex: rather than setting, Search | Enable Regex.
Post Reply