Regular Expressions Example

If you want to use regular expressions to know if some numerical value is higher then 199 use the following code:

^\d{1,2}$|^[1]\d\d$

Explanation:

^          = String begins with

\d         = numerical string (character 0-9)

{1,2}    = minimal 1 maximum 2 numerical characters

$          = end script

|           = OR (to bind 2 regular expressions)

^          = begins with

[1]        = first character = 1 (if you want to go till 299 it may be [1-2])

\d\d      = the next 2 character must be numerical strings

$          = end

For 399 the parameter can be:

^\d{1,2}$|^[1,2,3]\d\d$

or

^\d{1,2}$|^[1-3]\d\d$

Nice freeware regex tool: http://www.radsoftware.com.au/regexdesigner/

Lot of samples: http://www.regular-expressions.info/examples.html

Online test: http://www.regexplanet.com/simple/index.html

Hope this helps 🙂

Author: Thomas Faddegon

Bla bla bla