日期:2014-05-17  浏览次数:20508 次

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

<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