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

正则 截取固定开头结尾字符串中间的字符串
比如:class="g">topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 </span> - <a
其中以class="g">开头 ;</span> - <a结尾如何获取中间的字符串:topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 。


------解决方案--------------------
C# code

        string str = "class="g">topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 </span> - <a";
        Regex reg = new Regex(@"(?s)(?<=class=&quot;g&quot;&gt;).*(?=&lt;/span&gt; - &lt;a)");
        foreach (Match m in reg.Matches(str))
        {
            Response.Write(m.Value + "<br/><br/><br/><br/>");
        }
//topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28

------解决方案--------------------
探讨
C# code

string str = "class=&amp;quot;g&amp;quot;&amp;gt;topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 &amp;lt;/span&amp;gt; - &amp;lt;a";
Regex reg = new Regex(@"(?s)(?<……