㈠ 正則表達式過濾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標簽內空格
varhtml='<div><pdata-text-id="0"style="position:absolute;">在這里輸入內版容權</p></div>';
vartext=html.replace(/s+([^<>]+)(?=<)/g,function(match){returnmatch.replace(/s+/g,' ');});
㈢ html中去除某個標簽的style,用js怎麼去除空行還有段落
jquery可以用css函數
$("#id").css("屬性","參數值");
js應該差不多。
反正原理都是先獲取這個dom節點然後再獲取裡面的屬性然後再set值的。
jquery,js就是這么個意思
㈣ 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|][r|R]/*>)+|(<[p|P](.|/n)*?>)",
"
");
//
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如何過濾div內某特定HTML標簽
//這里為了方便使用jQuery
//移除使用tag類的div標記下的strong標記下a標記下沒有子回元素(鏈接為空答)的節點元素
jQuery('div.tagstronga:empty').parent().remove();
㈥ javascript 如何把html中所有<a>標記中的空格 全部替換成 
window.onload = function () {
var allA = document.getElementsByTagName("a"); //獲取所有a標簽
for (var i = 0; i < allA.length; i++) { //循環所有a標簽
var a = allA[i]; //獲取當前循環的a標簽
a.innerHTML = a.innerHTML.replace(/ /g, " "); //替換所有的空格為
}
}
放在頭部就內行了~
希望對您有幫助~容
By Billskate
㈦ 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標記
}
㈧ 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過濾標簽的方法。分享給大家供大家參考,具體如下:
<!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標簽
你可以利用正則表達式來剔除這些標簽,也就是將所有的html類的標簽都替換為空即可:
//去除HTML標簽
str=str.replace(/</?[^>]*>/g,'');