1

我有这段 HTML:

</TABLE>
<HR>
<font size="+1"> Method and apparatus for re-sizing and zooming images by operating directly
     on their digital transforms
</font><BR>

我正在尝试捕获font标签内的文本。这是我的正则表达式:

  Regex regex = new Regex("</TABLE><HR><font size=\"+1\">(?<title>.*?)</font><BR>", RegexOptions.Singleline | RegexOptions.IgnoreCase);

        Match match = regex.Match(data);

        string title = match.Groups["title"].Value;

但是我得到空标题。谁能告诉我我错过了什么?

4

1 回答 1

3

你的正则表达式;

new Regex("</TABLE><HR><font size=\"+1\">(?<title>.*?)</font><BR>"

格式不正确,因为+在正则表达式中有不同的含义。

根据您的输入字符串,您真正想要的是将其转义;

new Regex("</TABLE><HR><font size=\"\\+1\">(?<title>.*?)</font><BR>"

另外,如果你想用换行符匹配字符串,你也必须给一个通配符来忽略它们,所以这可能是你想要做的更多;

new Regex("</TABLE>.*<HR>.*<font size=\"\\+1\">(?<title>.*?)</font>.*<BR>"
于 2012-08-12T12:07:25.577 回答