开发者

How to write regex to verify a comma delimited list of integers of unknown size?

开发者 https://www.devze.com 2023-02-15 18:03 出处:网络
308091,1213,13414,12132,14431,14343,234,4334,2,34234,2344,32424 should match, preferably if I could verify also that there was NO trailing comma that would be grand... not sure how I would write thi
308091,1213,13414,12132,14431,14343,234,4334,2,34234,2344,32424

should match, preferably if I could verify also that there was NO trailing comma that would be grand... not sure how I would write this or if it would even be possible... letters should fail, any symbols besides numbers and commas should fail, any number of integers should be possible from one '12345' or two '12345,12345' and on to infinity '12345,98765,...'

go开发者_Python百科od luck


If you want only numbers (so 0123 wouldn't work) then you could use this pattern:

^([1-9][0-9]*,)*[1-9][0-9]*$


You can also use:

^[0-9]+(?:,[0-9]+)*$
0

精彩评论

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