Hi,
i need a regex for: 123,456,789,123,4444,..
. basically comma separated values. The INT part can be 1-4 numbers long, followed by a comma...always in this form...
/^([0-9]{1,4})(\,)?$/
This obviously doesn't work...
Thanks!
Hi,
i need a regex for: 123,456,789,123,4444,..
. basically comma separated values. The INT part can be 1-4 numbers long, followed by a comma...always in this form...
/^([0-9]{1,4})(\,)?$/
This obviously doesn't work...
Thanks!
Try this:
/^[0-9]{1,4}(?:,[0-9]{1,4})*$/
This will match any comma separated sequence of one or more digit sequences with one to four digits. (?:…)
is a so called non-capturing group that’s match cannot be referenced separately like you can with “normal” capturing groups (…)
.
Try this:
/^\d{1,4}(?:,\d{1,4})*+$/D
This will match any comma-separated sequence of one or more digit sequences with one to four digits. The D
modifier makes sure that any trailing newline character does not mistakenly result in a positive match.