㈠ 正则表达式过滤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,'');