我正在尝试创建一个接受的正则表达式:空字符串,单个整数或由逗号分隔的多个整数,但不能有起始和结束逗号.
我设法找到了这个,但我不能取消和如何删除数字限制
^\d{1,10}([,]\d{10})*$
Run Code Online (Sandbox Code Playgroud)
tst*_*ter 35
你发布的东西仍然需要至少1个整数,所以它不匹配空字符串:
这是你需要的:
^(\d+(,\d+)*)?$
Run Code Online (Sandbox Code Playgroud)
阐释:
'?'匹配空字符串结束.'\d+'. 这是一个或多个数字字符('0'-'9')',\d+'并在其后面加上星号.Hench整个事情是 either an empty string or start with an integer then repeat zero or more times a string which starts with a comma and ends with an integer