日期:2014-05-17 浏览次数:20994 次
Regex reg = new Regex(@"\b4159\S+\s+\S+"); MatchCollection mc = reg.Matches(Dat_Example); foreach (Match m in mc) { richTextBox2.Text += m.Value + "\n"; } /*-----输出----- 415915101216390725000AnHG<2VS 0031 415915101216390725100AnHG<2VS 0031 415915101216390725200 0031 415915101216390725300AnHG<2VS 0031 */
------解决方案--------------------
string Dat_Example = "8501151012172100711111 2000071111111 899999999 05I41714 2100100 LBD9 0000 G 490200000000000000H0363700000898600910909F8180750 5956 899900000033330010160008000000000000000000000000000101 415915101216390725000AnHG<2VS 0031 415915101216390725100AnHG<2VS 0031 415915101216390725200 0031 415915101216390725300AnHG<2VS 0031 0799EOF "; List<string> list=new List<string>(); foreach (Match m in Regex.Matches(Dat_Example,@"\b4159[^\s]+\s+[^\s]+\b")) { list.Add(m.Value); } list.Foreach(x=>Console.WriteLine(x)); /* 415915101216390725000AnHG<2VS 0031 415915101216390725100AnHG<2VS 0031 415915101216390725200 0031 415915101216390725300AnHG<2VS 0031 */
------解决方案--------------------
(?i)\b[A-Z\d]{2}59[^\s]+\s+[^\s]+\b
------解决方案--------------------
string pattern=@"\b[a-zA-Z0-9]{2}59[^\s]+\s+[^\s]+\b";
这样即可