日期:2014-05-18  浏览次数:20699 次

求一个正则,功力太差,拼不出来了
得到一个string test="
\n\t\t\t\t@\n\t\t\t\t1|\n\t\t\t\t完成\n\t\t\t\t@\n\t\t\t\t2|\n\t\t\t\t末完成\n\t\t\t\t@\n\t\t\t\t3|\n\t\t\t\t提交中"


Regex regexAsiaInfoMain = new Regex(@"@\s*(?'code'[^<]+)|\s*(?'name'[^<]+)\s*");
MatchCollection sections = regexAsiaInfoMain.Matches(test);
我想把1 完成 2 末完成 3提交中给匹配出来。
当然也有可能不止三个,或者少于3个。
请教下怎么拼~~~

------解决方案--------------------
C# code
  string test = @"\n\t\t\t\t@\n\t\t\t\t1|\n\t\t\t\t完成\n\t\t\t\t@\n\t\t\t\t2|\n\t\t\t\t末完成\n\t\t\t\t@\n\t\t\t\t3|\n\t\t\t\t提交中";
            string pattern = @"(?i)(\d+)\|.*?([\u4e00-\u9fa5]+)";
            foreach (Match m in Regex.Matches(test, pattern))
            {
                string code = m.Groups[1].Value;//1
                string name = m.Groups[2].Value;//完成
            }

------解决方案--------------------
C# code
        string s = "\n\t\t\t\t@\n\t\t\t\t1|\n\t\t\t\t完成\n\t\t\t\t@\n\t\t\t\t2|\n\t\t\t\t末完成\n\t\t\t\t@\n\t\t\t\t3|\n\t\t\t\t提交中";
        MatchCollection matches = Regex.Matches(s, @"(\d+)\|\n\t+(\S+)");
        foreach (Match match in matches)
        {
            Response.Write(match.Groups[1].Value + ":" + match.Groups[2].Value + "<br/>");
        }