当前位置:编程学习 > C#/ASP.NET >>

网页中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
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,