<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
var str1 = "AbcBCadfg";
var reg = new RegExp("ab", "i");
var isOK = reg.test(str1);
console.log(isOK);
var reg1 = /ab/i;
console.log("简写形式:" + reg1.test(str1));
var r1 = /\d/;
console.log("是否包含数字", r1.test("1abcdefg"));
var r2 = /\D/;
console.log("是否包含非数字", r2.test("78*78979"));
var r3 = /\w/;
console.log("是否包含数字或字母或下划线", r3.test(" _&&**"));
var r4 = /\W/;
console.log("是否包含非数字字母下划线", r4.test("738jhj=+kj_3_"));
var r5 = /\s/;
console.log("是否包含空白", r5.test("666 "));
var r6 = /\S/;
console.log("是否包含非空白", r6.test(" j"));
var r7 = /./;
console.log("是否包含非换行", r7.test("abc"));
var r8 = /\./;
console.log("是否包含.这个字符串", r8.test("a.bc"));
var r9 = /d/;
console.log("是否包含字母d", r9.test("adbc"));
var r10 = /ab\b/;
console.log("单词边界是否是ab", r10.test("cb ccc"));
console.log("单词边界是否是ab", r10.test("cb cab ggg"));
console.log("单词边界是否是ab", r10.test("cb ccc abc"));
var r11 = /[ab]/;
console.log("是否包含a或者b", r11.test("sssagg"));
console.log("是否包含a或者b", r11.test("bbbbc"));
var r12 = /[a-zA-Z0-9_]/;
console.log("是否包含数字大小写字母或者_", r12.test(" ..s..???+++"));
var r13 = /ab{2,8}/;
console.log("是否包含a而且b至少2最多6次", r13.test("abbbbb hjk"));
var r14 = /(ab){2,6}$/;
console.log("是否包含ab,2-6次", r14.test("ababababababababababababab 必须连在一起至少两遍"));
var r15 = /a{2,}/;
console.log("是否包含a至少连续2次", r15.test("abaaaa"));
var r16 = /^[a-z]{6}/;
console.log("是否以小写字母开头", r16.test("asfsfds23zbsd"));
var r17 = /(com)$|(cn)$/;
console.log("是否以com或者cn为结尾", r17.test("abc345cn"));
var r18 = /^1[3-9]\d{9}$/;
console.log("手机号", r18.test("132345678987"));
var r19 = /^[a-zA-Z]\w{5,15}$/;
console.log("密码6-16位,数字不可开头", r19.test("abca_bn"));
var r20 = /^\d+$/;
console.log("正数", r20.test("2a34"));
var r21 = /^\-?\d+\.\d+$/;
console.log("是否是小数", r21.test("28.89"));
var r22 = /^http:\/\//;
console.log("是否以http://开头", r22.test("http:/www.baidu.com"));
</script>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7e5ff29c30f2c53340d1fddc0f205640.png)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
var str1 = "abcdfgabdjfabdkfab";
var r1 = /ab|f/g;
var s1 = str1.replace(r1, "**");
console.log(s1);
var a = str1.match("ab");
console.log(a);
var a = str1.match(/ab|g|f/g);
console.log(a);
str1 = "你说什么狗子?你想吃骨头?不爱吃骨头的狗子不是好狗子!";
var a = str1.search("狗子");
console.log(a);
a = str1.search(/狗子|骨头/g);
console.log(a);
a = str1.split("狗子");
console.log(a);
a = str1.split(/狗子|骨头/);
console.log(a);
</script>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1c59fbf9b203e1d8cddea1e4fd986ca9.png)