e 1 سال پیش
والد
کامیت
75a76c38eb
5فایلهای تغییر یافته به همراه100 افزوده شده و 1 حذف شده
  1. 1 1
      正则/7.案例.html
  2. 28 0
      正则/晚课/1.认识正则表达式.html
  3. 18 0
      正则/晚课/2.修饰符.html
  4. 43 0
      正则/晚课/3.元字符-边界符.html
  5. 10 0
      正则/晚课/笔记.md

+ 1 - 1
正则/7.案例.html

@@ -21,7 +21,7 @@
         const str1 = "#f00";
         const str1 = "#f00";
         const reg2 = /^#([a-fA-f0-9]{6})|([a-fA-f0-9]{3})$/
         const reg2 = /^#([a-fA-f0-9]{6})|([a-fA-f0-9]{3})$/
         console.log(reg2.test(str1))
         console.log(reg2.test(str1))
-        // 4.匹配24小时时间 23:59 20:12 08:35 
+        // 4.匹配24小时时间 23:59 20:12 08:35 18:22
         const reg4 = /^([0-1][0-9])|([2][0-3]):[0-5][0-9]$/;
         const reg4 = /^([0-1][0-9])|([2][0-3]):[0-5][0-9]$/;
         console.log(reg4.test("12:36"))
         console.log(reg4.test("12:36"))
         console.log(reg4.test("20:12"))
         console.log(reg4.test("20:12"))

+ 28 - 0
正则/晚课/1.认识正则表达式.html

@@ -0,0 +1,28 @@
+<!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>
+        const reg = /西游记/g;
+        // 1.test()
+        const result = reg.test("这是一本西游ddd记");
+        console.log(result);
+        // 2.exec()
+        const result1 = reg.exec("这是一本西游记,西游记");
+        console.log(result1);
+        // 3.replace()
+        var str = '一段西游记的文字';
+        const result2 = str.replace(reg,'红楼梦');
+        console.log(result2);
+        // 4.match()
+        var str1 = '一本书西游记,我也爱看西游记,西游记呀';
+        const result3 = str1.match(reg);
+        console.log(result3);
+
+    </script>
+</body>
+</html>

+ 18 - 0
正则/晚课/2.修饰符.html

@@ -0,0 +1,18 @@
+<!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>
+        const reg = /an/g;
+        console.log(reg.test('aA'));
+        console.log(reg.test('aab'));
+        console.log(reg.test('aba'));
+        var str = 'an Apple,an Egg'
+        console.log(str.match(reg));
+    </script>
+</body>
+</html>

+ 43 - 0
正则/晚课/3.元字符-边界符.html

@@ -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>

+ 10 - 0
正则/晚课/笔记.md

@@ -0,0 +1,10 @@
+## 正则
+定义正则:const 变量名 = /表达式/;
+1.test() 判断正则表达式与指定字符串是否相匹配 返回布尔值
+2.exec() 查找符合规则的字符串
+3.replace() 用来替换字符串中符合规定的字符
+4.match() 在字符串中找到符合规则的字符,找到一个或多个并返回
+
+### 修饰符
+i 匹配时不分大小写
+g 匹配全局