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.
我有以下字符串:
10-0 5-8 1-19
如果字符串包含 [num]-[num],我想得到一个“True”,否则它应该返回“False”。
我应该如何使用正则表达式?
它应该是这样的^((\d+)-(\d+))$
^((\d+)-(\d+))$
Regex objPattern=new Regex(@"((\d+)-(\d+))$"); bool val = objPattern.IsMatch("12-34");
我不知道如何在 c# 中使用正则表达式,但这里有一个与您的模式匹配的正则表达式:\d+-\d+
\d+-\d+
Regex reg = new Regex(@"(\d+)-(\d+)")