码迷,mamicode.com
首页 > Windows程序 > 详细

c# 正则表达式分组

时间:2016-06-21 15:27:18      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:

internal class Program
{
private static void Main(string[] args)
{

var content = Read(@"E:\workspace\日志\2016-06-21.LOG2016-06-21.LOG");
Regex reg3 = new Regex(@"手机号(?<result>(\d+)?)");
var matches = reg3.Matches(content);
if (matches.Count > 0)
{
var list = new List<string>();
string phone;
foreach (Match item in matches)
{
phone = item.Result("${result}");
if (list.Contains(phone))
{

}
else
{
list.Add(phone);
}
}
}
}

public static string Read(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
StringBuilder sb = new StringBuilder();
while ((line = sr.ReadLine()) != null)
{
sb.AppendLine(line);

}
return sb.ToString();

}
}

c# 正则表达式分组

标签:

原文地址:http://www.cnblogs.com/zhshlimi/p/5603427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!