62,046
社区成员
发帖
与我相关
我的任务
分享
//验证用
Regex re = new Regex(@"^abc\s+\d+(\.\d+)[^\s]+\s+bbb$", RegexOptions.None);
if (re.IsMatch("你要验证的字符串"))
{
//符合
}
else
{
//不符合
}
//提取用
string str = "abc 12.34aaa bbb";
Regex re = new Regex(@"abc\s+((\d+(\.\d+)?)([^\s]+))\s+bbb", RegexOptions.None);
Match ma = re.Match(str);
//ma.Groups[0].Value; 结果:abc 12.34aaa bbb
//ma.Groups[1].Value; 结果:12.34aaa
//ma.Groups[2].Value; 结果:12.34
//ma.Groups[4].Value; 结果:aaa