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.
このようなものを検証する必要があります
12,14,15,18-20,23,50-130
私はこれについて考えます:
^(?:\\d[,] | \\d[-])$ // or ^(?:\\d[,] | \\d[-] *)$ ??
編集 それはのために働くはずです
12, 15 11,13, 14,18, 51-52
それはのために働くべきではありません
w,12 12,15d 14,,18 14--20 12,12- -12,13 ,12 12, 13-, -,13
まず、二重のバックスラッシュを避けるために逐語的な文字列を使用します。そして、これはあなたのために行うかもしれません:
@"^\s*\d+(?:-\d+)?\s*(?:,\s*\d+(?:-\d+)?\s*)*$"
それは数字で、オプションでハイフン番号が続きます。そして、任意の量の,, 空白と再び最初のパターン。
,
これを試すこともできます
@"^\s*\d+(\s*[,-]\s*\d+)*\s*$"