Page 1 of 1

Regex: Search for numbers

Posted: Fri Jul 05, 2019 9:14 pm
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]$

Re: Regex: Matching number ranges

Posted: Fri May 08, 2020 8:47 pm
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!

Re: Regex: Search for numbers

Posted: Sat May 09, 2020 3:07 pm
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.