Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何为我的输入编写正则表达式。我的输入是
1-10,11-25,26-32,46-83 或 1-24,28,25-27
健康)状况:
必须以数字开头和结尾。没有逗号或连字符。
没有两个 ,, 或 -- 存在
谢谢提前
像这样的东西应该可以工作:^(\d+(-\d+)?)(,\d+(-\d+)?)*$.
^(\d+(-\d+)?)(,\d+(-\d+)?)*$
它应该匹配一个或多个数字,后跟(可选)破折号和一个或多个数字。这又是 0 次或多次后跟一个逗号和一个或多个数字,可选地后跟一个破折号和一个或多个数字。