e il y a 1 mois
Parent
commit
46175087ba

+ 39 - 0
17.正则/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>
+        // 任意匹配 []
+        // const reg = /[abc]/;
+        // console.log(reg.test("ababab"));
+        // console.log(reg.test("abc"));
+        // console.log(reg.test("acbcba"));
+        // console.log(reg.test("acaacac"));
+        // console.log(reg.test("dcdhjhfgjk"));
+
+        // 连字符 -
+        // const reg1 = /[0-9]/
+        // const reg2 = /[a-f]/
+
+        // 取反 ^
+        // const reg3 = /[^a-z]/;
+        // console.log(reg3.test("acaacac"));
+        // console.log(reg3.test("uiuiui"));
+        // console.log(reg3.test("ba8ba"));
+        // console.log(reg3.test("as"));
+
+        // . 除换行以外的任意字符
+        const reg4 = /./;
+        console.log(reg4.test('aaa'))
+        console.log(reg4.test('123456789'))
+        console.log(reg4.test(''));//false
+        console.log(reg4.test('\n'))
+        console.log(reg4.test('\r'))
+
+    </script>
+</body>
+</html>

+ 33 - 0
17.正则/6.元字符-分组.html

@@ -0,0 +1,33 @@
+<!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)c/;
+        console.log(reg.test("abcabdcba")); //false
+        console.log(reg.test('ab')); // false
+        // 2025-03-29
+        const data = '2025-03-29';
+        // 03/29/2025
+        const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/
+        console.log(reg1.test(data));
+        // $1 $2 $3
+        // 分组捕获
+        console.log(data.replace(reg1,'$2~$3~$1'))
+        // 分支结构
+        const a1 = 'www';
+        const a2 = 'aaa';
+        const a3 = 'vvv';
+        const a4 = 'ggg';
+        const reg2 = /www|ggg/;
+        console.log(reg2.test(a1));
+        console.log(reg2.test(a2));
+        console.log(reg2.test(a3));
+        console.log(reg2.test(a4));
+    </script>
+</body>
+</html>

+ 16 - 0
17.正则/7.案例.html

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

BIN
17.正则/元字符.jpg