当前位置: 代码迷 >> ASP.NET >> 正则 截取固定开头结尾字符串中间的字符串,该怎么解决
  详细解决方案

正则 截取固定开头结尾字符串中间的字符串,该怎么解决

热度:9333   发布时间:2013-02-25 00:00:00.0
正则 截取固定开头结尾字符串中间的字符串
比如: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=&quot;g&quot;&gt;topic.csdn.net/u/20091018/11/ef331a56-93f ... 2011-3-28 &lt;/span&gt; - &lt;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)(?<……
  相关解决方案