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.
我正在尝试匹配仅包含带有逗号的数字和带有连字符的数字的字符串,例如,
应该匹配,
22-10,3,34-2,16 22,10,3,34,2,16 22-10-3-34-2-16 23-10,6
不应该匹配,
4ABS-NTts ABS,NT 2
任何帮助都会非常有帮助
尝试这个:
^(?:[0-9]+[,-])+[0-9]+$
解释:
^ # Start of string (?: # Try to match: [0-9]+ # one or more digits [,-] # one separator (- or ,) )+ # once or more. [0-9]+ # Match one or more digits $ # End of string
^(?:\d+[,-]?)+\d+$
它也匹配裸数字23。 您可以在此站点中对其进行测试。
23