110,566
社区成员
发帖
与我相关
我的任务
分享
//验证
^\[\d+\]-\[\d+\]$
//提取
\[\d+\]-\[\d+\]
string testStr = @"[12]-[34]";
Regex objRegex = new Regex(@"^\[(\d+)\]\-\[\d+\]$");
Match objMatch = objRegex.Match(testStr);
if (objMatch.Success) {
//objMatch.Groups[1].Value 这就是需要的
}
MatchCollection mc = Regex.Matches(src, @"[\d+]-[\d+]");
foreach(Matche m in mc)
{
Console.WriteLine(m.value);
}
Match match = Regex.Match(str2, @"\[\d+]-\[\d+]");
Match match = Regex.Match(str2, @"[\d+\]-[\d+\]");
@"[\d{1,}]-[\d{1,}]"