user1792859
user1792859

Reputation: 37

Regular Expression for numericals

Hi People I am very new at Regex. I found out that 0-99 has expression "(?:\b|-)([1-9]{1,2}[0]?|99)\b" and 100-200 has "[1-2]\d\d".

I wanted to find out how it would be to write a range 9990001 - 9999991.

Any answer which makes it work would be gladly appreciated. Thanks

Upvotes: 0

Views: 112

Answers (2)

online Thomas
online Thomas

Reputation: 9381

You can use

999[0-9]{2}([0-8][0-9]|91|90)

999 litteral

[0-9]{2} 2 numbers

([0-8][0-9]|90|91) 0 to 8 with any number or 91 or 90

Test it yourself

p.s. I agree with @ikleschenkov That you should just use an if stament with that range when possible. Regex is not the best (and not even fastest) tool for this kind of problem.

Upvotes: 2

Ori Marko
Ori Marko

Reputation: 58772

You have 3 options with 0X (X more than 0) , 1-8X and 9X (X up to 1):

999[0-9][0-9][0][1-9]|999[0-9][0-9][1-8][0-9]|999[0-9][0-9][9][0-1]

Upvotes: 0

Related Questions