开发者

regex int + comma

开发者 https://www.devze.com 2023-01-11 02:43 出处:网络
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...

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 doe开发者_JAVA百科sn't work...

Thanks!


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.


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 (…).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号