正则表达式之Regex.Match()用法

//匹配字符串中的连续数字
string txt = "AAA12345678AAAA";
string m = Regex.Match(txt, @"\d+").Value;
Console.WriteLine(m);

 正则表达式中()是代表分组

 例如:(\d{1})(\d{1}) 整个表达式是第一组,第一个括号是第二组,第二个括号是第三组。提取方式跟数组一样

 获取值写法:Groups[1].Value 第一个括号里的值、Groups[2].Value 第二个括号里的值

//匹配字符串中的连续数字(前三位数字)
string txt = "AAA12345678AAAA";
string m = Regex.Match(txt, @"(\d{3})(\d{1,})").Groups[1].Value;
Console.WriteLine(m);

 

来源:中国建筑市场网

posted @ 2016-04-01 10:06  苦逼的猿人  阅读(6567)  评论(0编辑  收藏  举报