首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

正则,功力太差,拼不出来了

2012-05-01 
求一个正则,功力太差,拼不出来了得到一个string test\n\t\t\t\t@\n\t\t\t\t1|\n\t\t\t\t完成\n\t\t\t\t@

求一个正则,功力太差,拼不出来了
得到一个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/>");        } 

热点排行