1. 程式人生 > >js正則表示式去除HTML標籤

js正則表示式去除HTML標籤

1,得到網頁上的連結地址:

string matchString = @"<a[^>]+href=\s*(?:'(?<href>[^']+)'|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>";
2,得到網頁的標題:
string matchString = @"<title>(?<title>.*)</title>";
3,去掉網頁中的所有的html標記:
string temp = Regex.Replace(html, "<[^>]*>", ""); //html是一個要去除html標記的文件

4, string matchString = @"<title>([\S\s\t]*?)</title>";
5,js去掉所有html標記的函式: 
function delHtmlTag(str)
{
return str.replace(/<[^>]+>/g,"");//去掉所有的html標記
}