网页中Title的正则表达式
需要分页一个页面的title如
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
页面标题
</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
----------------------------------------------
注意,这里需要找到匹配的字符串为:
<title>之间是有换行和空格的
--------------------编程问答-------------------- (?<=<title>)(.|\s)*(?=\</title>) --------------------编程问答-------------------- (?<=<title>)(.|\s)*(?=</title>) --------------------编程问答-------------------- <title>(.*?)</title> --------------------编程问答--------------------
--------------------编程问答-------------------- 记得引用
string s = .......;//设文本在这个变量
string ptn = "<title>((.|\n)*)</title>";
Match match = Regex.Match(s, ptn, RegexOptions.IgnoreCase);
if (match.Success)
TextBox1.Text = match.Groups[1].Value;
using System.Text.RegularExpressions;
--------------------编程问答-------------------- 3楼正确 --------------------编程问答-------------------- 3楼的可以,给你一个效率高一点的
string Pattern = "(?<=<title>)[^<]+";
Match m = Regex.Match("处理字符串",Pattern);
if(m.Success)
{
Response.Write(m.Value);
}
补充:.NET技术 , ASP.NET