regex

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Is there a simple regex expression which matches three comma separated
values? (0-255,0-255,0-255)
 
Well, "simple" is a relative word :).

Below are some options available. Let me know if you find any issues with
them:

Matches 3 comma delimited number without leading zeros. The value "255,1,06"
will not match because the 6 is preceded by the zero.
(?=^\d+\,\d+\,\d+$)^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\,?){3}$

Matches 3 comma delimited number with leading zeros. The value "255,1,06"
will match:
(?=^\d+\,\d+\,\d+$)^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\,?){3}$

Of course, there is always the boring and simpler way :). Matches 3 comma
delimited number with leading zeros. The value "255,1,06" will match:
^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?),(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?),(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

Cheers
Rene
 
Back
Top