正则疑惑
问题是。我想获取一个带样式class="yuna" 的 <A>连接的地址 ,也就是 “http://www.yuna123.com”现在错误,帮我改改
default.aspx 文件
<div>
<asp:TextBox ID="TextBox1" runat="server" Height="311px" TextMode="MultiLine" Width="609px"></asp:TextBox>
</div>
default.cs 文件
protected void Page_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(Server.MapPath("~/my.html"));
string body = sr.ReadToEnd();
sr.Close();
Match m = Regex.Match(body,@"<a href=\""(.*?)\"" class=\""yuna\"">",RegexOptions.IgnoreCase|RegexOptions.Singleline);
TextBox1.Text = m.Groups[1].Value;
}
my.html 文件
<table border="0" align="center">
<tr>
<td>
<br/><a href="http://www.google1.com" >google.com</a><br/>
<a href="http://www.google2.com" >google.com</a><br/>
<a href="http://www.google.com" >google.com</a><br/>
<a href="http://www.google2.com" >google.com</a><br/>
<a href="http://www.google3.com" >google.com</a><br/>
<a href="http://www.google.com" >google.com</a><br/>
<a href="http://www.yuna123.com" class="yuna">google.com</a><br/>
</td>
</tr>
</table>
--------------------编程问答-------------------- d --------------------编程问答-------------------- Match m = Regex.Match(body,@" <a href=\""(.*?)\"" class=\""yuna\"">",RegexOptions.IgnoreCase|RegexOptions.Singleline);
=============>
Match m = Regex.Match(body," <a href=\""(.*?)\"" class=\""yuna\"">",RegexOptions.IgnoreCase|RegexOptions.Singleline); --------------------编程问答-------------------- 什么意思 --------------------编程问答-------------------- 把那句换成
Match m = Regex.Match(body," <a href=\""(.*?)\"" class=\""yuna\"">",RegexOptions.IgnoreCase|RegexOptions.Singleline);
回头才发现大名DD的yuna竟然只给了10分 --------------------编程问答-------------------- 胡说,去掉@ 就语法错误了 --------------------编程问答-------------------- Match m = Regex.Match(body," <a href=\"(.*?)\"class=\"yuna\">",RegexOptions.IgnoreCase|RegexOptions.Singleline);
this the last answer --------------------编程问答-------------------- Match m = Regex.Match(body," <a href=\"(.*?)\" class=\"yuna\">",RegexOptions.IgnoreCase|RegexOptions.Singleline);
--------------------编程问答-------------------- 帮顶 --------------------编程问答--------------------
Match m = Regex.Match(body,@"(?is)<a href=\""([^>]*?)\""\s+class=\""yuna\"">");
补充:.NET技术 , ASP.NET