zheng 14 hours ago
parent
commit
9901e8f8d6
4 changed files with 84 additions and 0 deletions
  1. 39 0
      21.正则/5.字符类.html
  2. 29 0
      21.正则/6.分组.html
  3. 16 0
      21.正则/7.练习.html
  4. BIN
      21.正则/元字符.jpg

+ 39 - 0
21.正则/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("acbab"));
+         console.log(reg.test("acacacac"));
+         console.log(reg.test("ededfd"));
+
+        //  - 连字符
+         const reg1 = /0-9/;
+         const reg2 = /a-z/;
+         const reg3 = /A-Z/;
+         const reg4 = /a-zA-Z0-9_/;
+
+        //  ^ 取反
+        const reg5 =/[^0-9]/;
+        console.log(reg5.test('adad'));
+
+        // . 匹配换行外的任意字符
+        const reg6 = /./;
+        console.log(reg6.test('adad'));
+        console.log(reg6.test('12123'));
+        console.log(reg6.test(' '));
+        console.log(reg6.test('.'));
+        console.log(reg6.test('\t'));
+
+    </script>
+    
+</body>
+</html>

+ 29 - 0
21.正则/6.分组.html

@@ -0,0 +1,29 @@
+<!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)(cc)/;
+        console.log(reg.test('ababaccb'));
+        console.log(reg.test('abab'));
+        console.log(reg.test('abccab'));
+        console.log(reg.test('ababaccb'));
+
+        const data = '2026-01-30';
+        const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/;
+        console.log(reg1.test(data));
+        console.log(data.replace(reg1,'$2/$3/$1'));
+
+
+        const reg2 = /西游记|红楼梦/;
+        console.log(reg2.test("红楼梦"));
+        console.log(reg2.test("水浒传"));
+        // /^\d{15,17}$/
+        // https://regexper.com/ 网址
+    </script>
+</body>
+</html>

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

BIN
21.正则/元字符.jpg