I’m not very well versed with regular expressions. I’ve had to use them, maybe once every few years, and that was mostly for course work. Anyways, the following question should be a fairly straight forward question/answer for anyone familiar with regular expressions.
I need to ensure that the text entered into a field follows the following format:
x y z
or
x,y,z
or
x y z / <same pattern can repeat for almost unlimited length>
or
x,y,z / <...> // Spaces after the comma are ok
where x, y and z can only be integers. The patterns cannot be intermixed, so you cannot have
x, y, z / x y z / ...
I’ve tried the following
([1-9] [1-9] [1-9])
to get the x y z part, but I don’t know how to include the ‘/’ nor the ‘,’
Any suggestions?
I guess you can use
Spliting in smaller pieces
The second big parenthesis matches or not more iterations of this sequence if started by
/.If all separator needs to be exactly the same, replace them by
\\2(just don’t replace the first, that is what it is going to match for the group 2).