let strs = "哈哈哈哈哈哈哈哈哈哈哈jfkldsjalk,.23@#!$$k~! @#$%^&*()(_+-=|\{}[]';:,./<>??gg g~```gf";
strs = strs.replace(/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g,"");
let recxType = /^[0-9A-Za-z\u4e00-\u9fa5]{15,}$/
if (!recxType.test(strs)) {
alert('请输入大于15位汉字、字母、数字组成的的有害短信样本')
} else {
alert(strs);
}
strs = strs.replace(/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g,"");
let recxType = /^[0-9A-Za-z\u4e00-\u9fa5]{15,}$/
if (!recxType.test(strs)) {
alert('请输入大于15位汉字、字母、数字组成的的有害短信样本')
} else {
alert(strs);
}
<script language="javascript">
str='<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><br/ >';
str=str.replace(/<[^>]*>|/g,"");
alert(str);
</script>

本文介绍了一种使用 JavaScript 进行字符串处理的方法,重点在于如何利用正则表达式来清除文本中的特殊字符,并通过一个具体的例子展示了整个过程。

3794

被折叠的 条评论
为什么被折叠?



