導航:首頁 > 凈水問答 > js正則表達式過濾span

js正則表達式過濾span

發布時間:2021-02-08 16:53:53

㈠ 怎樣用正則表達式過濾掉頁面中除了<p></p>和<img>以外所有的標簽

這個還真不容易實現,單獨保留p或者img都可以,但是兩個條件放一起就不行了。於專是我換屬了一種思路,用了個函數實現了,你看下,代碼是python下的:

importre

t='<html>asdfasdf<head>1111111111<body><p>asdfasdfasdf</p><imgherf="fff">'
defreplace_two(m):
"""
#過濾掉頁面中除了<p></p>和<img>以外所有的標簽
"""
all=re.findall(r'</?.*?>',m)
save=re.findall(r'</?(?:img).*?>|</?[pP]*?>',m)

foreinall:
ifenotinsave:
m1=m.replace(e,'')
m=m1
returnm

printreplace_two(t)

㈡ 正則表達式過濾'_'下劃線。

這么寫就行了 不過有這個必要嗎
using System.Text.RegularExpressions;
string[] strArr = new string[] {
"aaa.kels_kwoo._lwie" ,
"aaa.kels kwoo.lwie",
"kels kwoo.lwie",
"kels kwoo._lwie"
};
Regex regex = new Regex("^[^_]+$");
foreach (string item in strArr)
{
if (regex.IsMatch(item))
{
Console.WriteLine(item);
}
}
Console.ReadKey();

㈢ Js字元串的正則匹配 如何過濾掉指定特徵的字元串

String.replace(正則表達式,"")
replace是string類型內置的替換方法,第一個參數可以是正則表達式,第二個版參數是想權要替換成的文本,正則中可以使用/g來表示替換所有匹配的文本,不使用則代表只替換匹配到的第一個字元對象,將第二個參數設為空字元串便可達到過濾的效果。
具體正則需要你自己去了解關於正則的知識了,祝你好運。

㈣ 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中用正則表達式 過濾特殊字元 校驗所有輸入域是否含有特殊符號

樓上2位已經說的很明白了,只允許輸入規定的字元,如果輸入含有其他字元就直接提示,不允許輸入特殊字元,或者直接給它替換掉。

㈥ 正則表達式獲取span中的值

^內容<input type="text" id="text" value="<span id=>e</span>"/><br/>
<input type="button" onclick="if(/<span[^>]*>[^<]*?<\/span>/.test(text.value)){alert(text.value.match(/<span[^>]*>[^<]*?<\/span>/))}else{alert('匹配不到結果!')}" value="正則表回達式驗證答" /><br/>

㈦ 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;
}

㈧ 在javascript中用正則表達式過濾指定的字元(一定要能指定!)

樓上的不加轉義字元\ 你們搞什麼啊
正確的應該是這樣的

加入你得到的內字元竄容為 name
<html>
<head>
<script>
function test1(){
var name=document.getElementById('user').value;
name=name.replace(/(\!+)|(\<+)|(\>+)|(\'+)/g,"");
alert(name);
}
</script>
</head>

<body>
<input type="text" id="user" />
<input type="button" value="te" onclick="test1()">
</body>
</html>

㈨ 如何用用正則表達式過濾html中所有 Script

用正則表達式過濾html中所有 的方法:
1、定義正則表達式:
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi
2、用正則表達式處理script的方法如下:
<html>
<head>
<!--此處引入script腳本用於測試開始-->
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
alert($("p").html());
});
});
</script>
<!--此處引入script腳本用於測試結束-->
</head>
<body>
<p>This is a paragraph.</p>
<!--這里增加一個按鈕,點擊後會刪除所有的script塊的代碼-->
<button class="btn1" onclick="removeAllScript();">刪除script</button>
</body>
</html>
<!--定義function處理刪除-->
function removeAllScript(obj){
//定義正則表達式,只要是存在於<script>和</script>之間的內容都會被刪除
var SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
while (SCRIPT_REGEX.test(obj)) {//傳入文檔對象,獲取整體內容
text = text.replace(SCRIPT_REGEX, ""); //正則替換為空
}
}

閱讀全文

與js正則表達式過濾span相關的資料

熱點內容
陶瓷膜過濾超濾納濾 瀏覽:145
樹脂眼鏡使用壽命 瀏覽:684
客車裡面的飲水機怎麼用 瀏覽:915
離子束去疤什麼費用 瀏覽:634
康佳品牌飲水機哪裡賣多少錢一台 瀏覽:856
超濾膜與反滲透膜的異同點 瀏覽:607
超濾排污 瀏覽:313
什麼東西洗凈水泥 瀏覽:173
凈水機配件行業前景怎麼樣 瀏覽:327
廢水中無機氮如何處理 瀏覽:646
制水機廢水管長流水什麼原因 瀏覽:227
全透明樹脂如何固化 瀏覽:354
元神純水精靈怎麼到40級 瀏覽:653
凈水機的水管怎麼關 瀏覽:126
酯化水處理可以用ro反透膜法嗎 瀏覽:47
污水廠cod去除率怎麼算 瀏覽:183
超濾與納濾區別表 瀏覽:609
紅外節能塗料用樹脂 瀏覽:192
地下室瓷磚廢水如何處理 瀏覽:948
九陽龍頭濾芯什麼型號 瀏覽:659