日期:2014-05-18 浏览次数:20843 次
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n"; StringBuilder sb=new StringBuilder(); Regex.Matchex(content,@"1[\d]{10}").OfType<Match>().Select(x=>x.Value).ToList().ForEach(x=>sb.Append(x+"\r\n"));
------解决方案--------------------
这样试试
string content = @"13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n"; StringBuilder sb = new StringBuilder(); MatchCollection mc = Regex.Matches(content, @"(13([0-9])|15([0-9])|18([0-9]))\d{8}"); foreach (Match m in mc) { sb.Append(m.Value + "\r\n"); }
------解决方案--------------------
两种方法
//一种是直接替换不必要的字符 string content = "1344090098114\r\n13440900985\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n"; Regex reg = new Regex(@"[^\r\n0-9]|[0-9]{12,}|(?<![0-9])[0-9]{1,10}(?![0-9])|(?!1[358][0-9]{9})[0-9]{11}"); string result = reg.Replace(content, "");
------解决方案--------------------
string content = "13440900984\r\n13440900984\r\n你好\r\n13440900984\r\n你好\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984\r\n13440900984你好\r\n鸟\r\n13440900984\r\n13440900984\r\n";
var query = content.Split(new string[] { "\r\n" }).AsParallel().Where(x => Regex.IsMatch(x, "1(3|5|8)\d{9}"));
使用PLinq,如果你有一个16核心的Intel CPU,那么大约可以提高1个数量级(10倍)速度。