郑柏铃 il y a 1 jour
Parent
commit
e0172333f1
2 fichiers modifiés avec 40 ajouts et 0 suppressions
  1. 23 0
      23.正则/1.认识正则表达式.html
  2. 17 0
      23.正则/2.修饰符.html

+ 23 - 0
23.正则/1.认识正则表达式.html

@@ -0,0 +1,23 @@
+<!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;
+        // 1.test() 匹配文中是否包含校验的字符 返回布尔值
+        console.log(reg.test("今天没有雨"));
+        // 2.exec() 返回数组格式 查找符合条件的字符
+        console.log(reg.exec("今天没有太阳,明天有太阳"));
+        // 3.replace() 替换指定字符
+        const str = '今天没有太阳,明天有太阳';
+        console.log(str.replace(reg,'雨'));
+        // 4.match() 在字符串中查找符合规则的字符
+        console.log(str.match(reg));
+    </script>
+</body>
+</html>

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

@@ -0,0 +1,17 @@
+<!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>
+        //  g 匹配全局
+        //  i 不区分大小写
+        const reg = /A/ig;
+        let str = 'I have an apple and A banana';
+        console.log(str.match(reg))
+    </script>
+</body>
+</html>