zheng il y a 1 jour
Parent
commit
850dacf457
3 fichiers modifiés avec 76 ajouts et 0 suppressions
  1. 39 0
      正则/5.元字符-字符类.html
  2. 18 0
      正则/6.分组.html
  3. 19 0
      正则/7.案例.html

+ 39 - 0
正则/5.元字符-字符类.html

@@ -0,0 +1,39 @@
+<!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. 任意匹配 []
+        // const reg = /[abc]/;
+        // console.log(reg.test("ababab"));
+        // console.log(reg.test("abc"));
+        // console.log(reg.test("acbacb"));
+        // console.log(reg.test("acacac"));
+        // console.log(reg.test("dfdfdf"));
+
+        // 2.连字符 -
+        const reg1 = /[0-9]/;
+        const reg2 = /[a-z]/;
+        const reg3 = /[A-Z]/;
+        const reg4 = /[a-zA-Z0-9_]/;
+        console.log(reg1.test(4))
+
+        // 3.取反 ^
+        const reg5 = /[^0-9]/
+        console.log(reg5.test(4))
+
+        // 4. . 除空格外的任意字符
+        const reg6 = /./;
+        console.log(reg6.test("aaa"));
+        console.log(reg6.test("1234567890"));
+        console.log(reg6.test(""));
+        console.log(reg6.test("\n"));
+        console.log(reg6.test("\r"));
+        
+    </script>
+</body>
+</html>

+ 18 - 0
正则/6.分组.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 str = '2025-09-18';
+        // 09/18/2025
+        const reg = /^(\d{4})-(\d{2})-(\d{2})$/;
+        console.log(reg.test(str))
+        console.log(str.replace(reg,'$2/$3/$1'))
+        // 分支结构: |
+    </script>
+</body>
+</html>

+ 19 - 0
正则/7.案例.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>