當前位置:首頁 » 凈水方式 » js正則過濾html標簽

js正則過濾html標簽

發布時間: 2021-02-16 09:16:28

『壹』 怎麼使用js過濾html標簽

你可以利用正則表達式來剔除這些標簽,也就是將所有的html類的標簽都替換為空即可:

//去除HTML標簽
str=str.replace(/</?[^>]*>/g,'');

『貳』 如何用正則表達式去掉html標簽

^protected void Page_Load(object sender, EventArgs e)
{
//string regexstr = @"<[^>]*>"; //去除所有的標簽
//@"<script[^>]*?>.*?</script >" //去除所有腳本,中間部分內也刪除
// string regexstr = @"<img[^>]*>"; //去除圖片的正容則
// string regexstr = @"<(?!br).*?>"; //去除所有標簽,只剩br
// string regexstr = @"<table[^>]*?>.*?</table>"; //去除table裡面的所有內容
string regexstr = @"<(?!img|br|p|/p).*?>"; //去除所有標簽,只剩img,br,p
str = Regex.Replace(str, regexstr, string.Empty, RegexOptions.IgnoreCase);
}

『叄』 js 正則表達式去除指定的HTML標簽

可以這么寫:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN""

<htmlxmlns="

<head>
<title>匹配正則表達式</title>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<scripttype="text/javascript">
functiont1(){
varcont=document.getElementById('cont');
varcv=cont.value;

varreg=/<a[s]+[^>]+>([^<>]+)</a>/gi;//正則表達式

alert(cv.replace(reg,''));
}
</script>

<styletype="text/css">
textarea{
width:400px;
height:200px;
}
</style>
</head>
<body>
<p>
<textareaid="cont"></textarea>
</p>
<p><inputtype="button"value="把鏈接換成空鏈接"onclick="t1();"/></p>
</body>
</html>

『肆』 js正則表達式過濾html標簽,這個正則式怎麼寫

|代碼雖短功能卻超強,運行效率也很高!
public static string ClearHtmlCode(string text)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
text = Regex.Replace(text, "[/s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|/n)*?>)", " "); //<br>
text = Regex.Replace(text, "(/s*&[n|N][b|B][s|S][p|P];/s*)+", " "); //
text = Regex.Replace(text, "<(.|/n)*?>", string.Empty); //any other tags
text = Regex.Replace(text, "/<//?[^>]*>/g", string.Empty); //any other tags
text = Regex.Replace(text, "/[ | ]* /g", string.Empty); //any other tags
text = text.Replace("'", "''");
text = Regex.Replace(text, "/ [/s| | ]* /g", string.Empty);
return text;
}

『伍』 如何使用js正則 過濾某一個html標簽下所有的標簽跟樣式呢只保留出純文本

js過濾HTML標簽的方法。分享給大家供大家參考,具體如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>無標題文檔</title>
<script>
window.onload=function()
{
varoTxt1=document.getElementById('txt1');
varoTxt2=document.getElementById('txt2');
varoBtn=document.getElementById('btn');
oBtn.onclick=function()
{
varreg=/<[^<>]+>/g;
oTxt2.value=oTxt1.value.replace(reg,'');
};
};
</script>
</head>
<body>
<textareaid="txt1"cols="40"rows="10"></textarea><br/>
<inputtype="button"value="過濾"id="btn"/><br/>
<textareaid="txt2"cols="40"rows="10"></textarea>
</body>
</html>

『陸』 JS 如何用正則替換指定HTML標簽

vars="<span>a</span>....<span>z</span>";
s=s.replace(/<span>(.*?)</span>/g,"<inputtype='text'value='$1'/>")

『柒』 正則表達式過濾html標簽和標簽中的注釋

|using System;
// 不過仔細看,我這個也沒錯啊...
// MyRule=@"<(?:[^><]|""[^""]""|'[^']')*>";
// 實際檢驗一下專:

using System.Text.RegularExpressions;

class Test
{
static void Main()
{
string s = @"<td onmouseover=""if (a > 0)"">abc</td>def";
string r = @"<(?:[^><]|""[^""]""|'[^']')*>";
string t = Regex.Replace(s, r, "");
Console.WriteLine(t); // 輸出:「屬 0)">abcdef」
}
}

『捌』 正則表達式如何過濾HTML標簽中的屬性值

去掉html標簽: str.replace(/</?[a-zA-Z]+[^><]*>/g,"")
去掉標簽裡面的屬性: str.replace(/<([a-zA-Z]+)\s*[^><]*>/g,"<$1>")
我親自測試通過,操作語言javascript 樓主內還有問容題的話Hi 我

『玖』 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標記
}

『拾』 JavaScript用正則表達式過濾 html 標簽

1:content=content.replace(/<\/?p[^>]*>/gi,'');//刪除所有的回<p>及</p>標簽答
2:content=content.replace(/<p[^>]*>/gi,'').replace(/<\/p>/gi,'<br />');

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239