Friday, 30 August 2013

Regular expression for 12;1;19-39;43

Regular expression for 12;1;19-39;43

I am new to regular expression and trying to match the following pattern
using regular expression:
1.Groups of numbers, each looks like either a single number like 12, or a
number range like 19-39
2.Groups are separated by semicolon(;)
3.All numbers are within range 1-48 (but we don't need to verify this in
regular expression)
So an example match would be 12;13;19-39;43
For a single group, I can think of using
\b[1-9]{1}|[1-9]{1}[0-9]{1}\b
for single number, and
\b[1-9]{1}|[1-9]{1}[0-9]{1}-[1-9]{1}|[1-9]{1}[0-9]{1}\b
for number range.
The question is how to take the semicolon(;) into consideration also: any
number of the above groups of number(s) connected by ; can be matched.
Thanks!

No comments:

Post a Comment