導航:首頁 > 凈水問答 > 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相關的資料

熱點內容
工廠污水對人體的危害 瀏覽:70
污水處理的ps怎麼用 瀏覽:270
三合一空調凈化器怎麼樣 瀏覽:668
美的飲水機濃縮水是什麼 瀏覽:641
樓下飲水機富氫和罐裝有什麼區別 瀏覽:2
污水處理技術員的自我介紹 瀏覽:773
污水處理廠小區多遠 瀏覽:122
環氧樹脂膠灌注磨具 瀏覽:909
離子交換樹脂被氧化 瀏覽:54
芒果加工廢水主要成分 瀏覽:479
化工類工業園區如何進行污水處理 瀏覽:898
鍋爐除垢劑優點 瀏覽:156
怎麼處理污水中的aox 瀏覽:999
污水治理中水回用 瀏覽:789
印染廢水氟化物 瀏覽:516
純水泥怎麼比例 瀏覽:263
無污水無廢氣如何環評 瀏覽:47
山工液壓油濾芯在什麼位置 瀏覽:327
污水廠統計上屬於什麼行業 瀏覽:560
卧式空調過濾段 瀏覽:277