Reputation: 714
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.
Upvotes: 0
Views: 8767
Reputation: 42667
Based on replies to the comments, it sounds like you need a regular expression for a pattern restriction in an XSD. According to the XSD spec, this should work:
default|[0-9]{4}(,[0-9]{4})*
Upvotes: 1
Reputation: 321638
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
Upvotes: 12