regex help, only one hyphen in a row? -
i want take 0-9
,
, -
so have:
[0-9-,]+
however want there ever 1 -
in row, can't have --
. how can this?
i think required 1 this:
^\d+(-\d+)?(,\d+(-\d+)?)*$
what is:
\d+
integer (one or more digits)
(-\d+)?
optional part matching -
followed integer
(,\d+(-\d+)?)*
0 or more occurrence of ,
followed combination of above mentioned patterns.
note: add together required escaping \
regex
No comments:
Post a Comment