e 1 年之前
父节点
当前提交
dcd3a38bed
共有 1 个文件被更改,包括 33 次插入0 次删除
  1. 33 0
      正则/6.分组.html

+ 33 - 0
正则/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)(cd)/;
+        console.log(reg.test('abaabbbdc'));
+        console.log(reg.test('abab'));
+        // 分组捕获 $1 $2 $3 
+        // 2024-04-17
+        const data = '2024-04-17'
+        const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/
+        console.log(reg1.test(data))
+        // 04/17/2024
+        console.log(data.replace(reg1,'$2~$3~$1'))
+        // 分支结构
+        const a1 = '西游记';
+        const a2 = '水浒传';
+        const a3 = '红楼梦';
+        const a4 = '三国演义';
+        const reg2 = /西游记|红楼梦/;
+        console.log(reg2.test(a1));
+        console.log(reg2.test(a2));
+        console.log(reg2.test(a3));
+        console.log(reg2.test(a4));
+    </script>
+</body>
+</html>