zheng 4 uur geleden
bovenliggende
commit
046c606a96
3 gewijzigde bestanden met toevoegingen van 78 en 0 verwijderingen
  1. 2 0
      15.正则/2.修饰符.html
  2. 24 0
      15.正则/3.边界符.html
  3. 52 0
      15.正则/4.量词.html

+ 2 - 0
15.正则/2.修饰符.html

@@ -9,6 +9,8 @@
 
 <body>
     <script>
+        // i 不区分大小写
+        // g 匹配全局
         const reg = /a/gi;
         const str = 'abcdea,a,A,A';
         console.log(reg.test(str));

+ 24 - 0
15.正则/3.边界符.html

@@ -0,0 +1,24 @@
+<!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 = /\baa\b/gi;
+        const str1 = 'hi aa djhshj';
+        console.log(str1.match(reg));
+
+        const reg2 = /^ab/;
+        console.log(reg2.test('abfghjklkjghfg'));
+
+        const reg3 = /ab$/;
+        console.log(reg3.test('abfghjklkjghfgab'));
+    </script>
+</body>
+
+</html>

+ 52 - 0
15.正则/4.量词.html

@@ -0,0 +1,52 @@
+<!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 = /a*$/;
+        // console.log(reg.test('aa'));
+        // console.log(reg.test(' '));
+        // console.log(reg.test('aab'));
+
+        // // ? 匹配零次或一次
+        // const reg = /a?$/;
+        // console.log(reg.test('aa'));
+        // console.log(reg.test(' '));
+        // console.log(reg.test('aab'));
+
+        // + 匹配一次或多次
+        // const reg = /a+$/;
+        // console.log(reg.test('aa'));
+        // console.log(reg.test(' '));
+        // console.log(reg.test('aab'));
+
+        // {n} 匹配n次
+        // const reg = /a{2}$/;
+        // console.log(reg.test('aa'));
+        // console.log(reg.test(' '));
+        // console.log(reg.test('aab'));
+
+        // // {n,} 匹配至少n次
+        // const reg = /a{2,}$/;
+        // console.log(reg.test('aa'));
+        // console.log(reg.test(' '));
+        // console.log(reg.test('aab'));
+        // console.log(reg.test('da'));
+        // console.log(reg.test('a'));
+
+        // {n,m} 匹配至少n次,至多m次
+        const reg = /a{0,2}$/;
+        console.log(reg.test('aa'));
+        console.log(reg.test(' '));
+        console.log(reg.test('aab'));
+    </script>
+</body>
+
+</html>