zheng 6 giờ trước cách đây
mục cha
commit
8dc11c19f5
3 tập tin đã thay đổi với 99 bổ sung0 xóa
  1. 50 0
      12.正则/4.字符类.html
  2. 30 0
      12.正则/5.分组.html
  3. 19 0
      12.正则/6.案例.html

+ 50 - 0
12.正则/4.字符类.html

@@ -0,0 +1,50 @@
+<!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 = /[abc]/;
+        // console.log(reg.test("ababab"))
+        // console.log(reg.test("abc"))
+        // console.log(reg.test("acacac"))
+        // console.log(reg.test("acbbca"))
+        // console.log(reg.test("dds"))
+
+        // - 连字符
+        // const reg1 = /0-9/;
+        // const reg2 = /a-z/;
+        // const reg3 = /A-Z/;
+        // const reg4 = /a-zA-Z0-9_/;
+
+
+        /**
+         * 
+         * \w => /a-zA-Z0-9_/
+         * \d => /0-9/
+         * \W => /[^a-zA-Z0-9_]/
+         * \D => /[^0-9]/
+         */
+
+        // 取反
+        // const reg = /\D/;
+        // console.log(reg.test('212'))
+
+        // . 匹配换行外的任意字符
+        const reg = /./;
+        console.log(reg.test("aaa"))
+        console.log(reg.test("1234567897654"))
+        console.log(reg.test("")) // false
+        console.log(reg.test("\n"))
+        console.log(reg.test("\r"))
+        console.log(reg.test("\f"))
+    </script>
+</body>
+
+</html>

+ 30 - 0
12.正则/5.分组.html

@@ -0,0 +1,30 @@
+<!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 = /(ab)(cd)(ef)/
+        console.log(reg.test("abcd"))
+        console.log(reg.test("xabcd"))
+        console.log(reg.test("abxcd"))
+        console.log(reg.test("abab"))
+        console.log(reg.test("abababaabdc"))
+        const data = '2026-08-27';
+        // 08/27/2026
+        const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/;
+        console.log(data.replace(reg1, '$2/$3/$1'));
+        const str2 = '红楼梦是四大名著之一'
+        const a1 = /西游记/
+        const a2 = /红楼梦/
+        const cc = /西游记|红楼梦/
+        console.log(cc.test(str2))
+    </script>
+</body>
+
+</html>

+ 19 - 0
12.正则/6.案例.html

@@ -0,0 +1,19 @@
+<!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>
+        // 1.手机号脱敏 13789430987 => 137****0987
+        // 2.密码匹配 (6-16字母、数字、下划线)
+        // 3.匹配16进制颜色 #ff0000 #0f0
+        // 4.匹配24小时时间 23:59 20:12 08:35 18:22
+    </script>
+</body>
+
+</html>