读书人

请问一正则表达式请!

发布时间: 2012-06-19 14:45:20 作者: rapoo

请教一正则表达式,请高手进!!!!

<div>
<a href="/common/pub.php?category=housing&type=1"
<a href="/comm234on/pu234b.php?category=housin13g&type=241"
</div>

这样一个字符串,要求找出""引号部分的字符串,得到结果:/common/pub.php?category=housing&type=1 /comm234on/pu234b.php?category=housin13g&type=241

请高手贴出代码,谢谢!!!

[解决办法]

C# code
            StreamReader reader = new StreamReader("e:\\1.txt");            string content = reader.ReadToEnd();            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"(?<=<a href=""[^""]*?)[^""]+(?="")");            System.Text.RegularExpressions.MatchCollection ms = reg.Matches(content);            foreach (System.Text.RegularExpressions.Match m in ms)            {                MessageBox.Show(m.Value);            }
[解决办法]
(?i)<a\b[^>]*href=(["'\s]?)(.*?)\1[^>]*>
取第二个分组,Groups[2].Value

读书人网 >asp.net

热点推荐