zheng 1 ngày trước cách đây
mục cha
commit
06ac8d016f
2 tập tin đã thay đổi với 42 bổ sung0 xóa
  1. 24 0
      正则/1.认识正则表达式.html
  2. 18 0
      正则/2.修饰符.html

+ 24 - 0
正则/1.认识正则表达式.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 字段名 = /需要校验的规则/
+        const reg = /西游记/g;
+        const str1 = '西游记,四大名著中有西游记';
+        // 1.test 匹配文本中是否包含校验的字段 返回布尔值
+        console.log(reg.test(str1));
+        // 2.exec 返回数组格式 查找符合规则的字符
+        console.log(reg.exec(str1));
+        // 3.replace 替换指定字符
+        console.log(str1.replace(reg,'红楼梦'));
+        // 4.match 查找字符串中符合规则的字符
+        console.log(str1.match(reg));
+    </script>
+</body>
+</html>

+ 18 - 0
正则/2.修饰符.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>
+        // i 不区分大小写
+        // g 匹配全局
+        var reg = /an/gi;
+        console.log(reg.test("An apple"));
+        var str = "An apple,an banana";
+        console.log(str.match(reg));
+    </script>
+</body>
+</html>