I need a regex for four-digit numbers separated by comma ("default" can also be a value).
Examples:
- 6755
- 3452,8767,9865,8766,3454
- 7678,9876
- 1234,9867,6876,9865
- default
Note: "default" alone should match, but default,1234,7656 should NOT match.
I need a regex for four-digit numbers separated by comma ("default" can also be a value).
Examples:
6755  3452,8767,9865,8766,3454  7678,9876   1234,9867,6876,9865  defaultNote: "default" alone should match, but default,1234,7656 should NOT match.
This should do it:
/^(default|\d{4}(,\d{4})*)$/
That's
^         start of string
(         start group
 default  literal "default"
 |        or
 \d{4}    digit repeated 4 times
  (       start group
   ,      literal ","
   \d{4}  four digits
  )       end group
 *        repeat 0 or more times
)         end group
$         end of string