|
@@ -0,0 +1,43 @@
|
|
|
|
+<!DOCTYPE html>
|
|
|
|
+<html lang="en">
|
|
|
|
+<head>
|
|
|
|
+ <meta charset="UTF-8">
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
+ <title>Document</title>
|
|
|
|
+</head>
|
|
|
|
+<body>
|
|
|
|
+ <script>
|
|
|
|
+ var str = "A Banana,see you again.see you tomorrow.A Cat"
|
|
|
|
+ // 1.单词边界
|
|
|
|
+ const reg = /\ba\b/gi;
|
|
|
|
+ console.log(str.match(reg))
|
|
|
|
+ // console.log(reg.test(str));
|
|
|
|
+ // 2. ^ 匹配字母首行
|
|
|
|
+ // const reg1 = /^h/;
|
|
|
|
+ // console.log(reg1.test("ahahaha"))//f
|
|
|
|
+ // console.log(reg1.test("hahahaah"))//t
|
|
|
|
+ // console.log(reg1.test("ch"))//f
|
|
|
|
+ // console.log(reg1.test("hc"))//t
|
|
|
|
+ // console.log(reg1.test("ddh"))//f
|
|
|
|
+ // console.log(reg1.test("hdh"))//t
|
|
|
|
+ // 3.$ 匹配字母尾行
|
|
|
|
+ // const reg2 = /ch$/;
|
|
|
|
+ // console.log(reg2.test("ahahaha"))//f
|
|
|
|
+ // console.log(reg2.test("hahahaah"))//t
|
|
|
|
+ // console.log(reg2.test("ch"))//t
|
|
|
|
+ // console.log(reg2.test("hc"))//f
|
|
|
|
+ // console.log(reg2.test("ddh"))//t
|
|
|
|
+ // console.log(reg2.test("hdh"))//t
|
|
|
|
+
|
|
|
|
+ const reg3 = /^hhhhhh$/
|
|
|
|
+ console.log(reg3.test("ahahaha"))//false
|
|
|
|
+ console.log(reg3.test("hahahaah"))//false
|
|
|
|
+ console.log(reg3.test("ch"))//false
|
|
|
|
+ console.log(reg3.test("hc"))//false
|
|
|
|
+ console.log(reg3.test("ddh"))//false
|
|
|
|
+ console.log(reg3.test("hdh"))//false
|
|
|
|
+ console.log(reg3.test(" "))//false
|
|
|
|
+ console.log(reg3.test("h"))//true
|
|
|
|
+ </script>
|
|
|
|
+</body>
|
|
|
|
+</html>
|