首页 > 代码库 > js 正则
js 正则
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<script>
var str = ‘runoob‘;
var patt1 = new RegExp(‘\\w‘, ‘g‘); // 有转义作为正则表达式处理
var patt2 = new RegExp(‘\w‘, ‘g‘); // 无转义作为字符串处理
var patt3 =/\w+/g; // 与 patt1 效果相同
document.write(patt1.test(str)) //输出 true
document.write("<br>")
document.write(patt2.test(str)) //输出 false
document.write("<br>")
document.write(patt3.test(str)) //输出 true
</script>
</body>
</html>
结果:
true
false
true
js 正则
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。