12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!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("abababacd"));
- console.log(reg.test("abab"));
- console.log(reg.test("abecd"));
- // 分组捕获
- const data = '2025-08-19';
- const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/;
- console.log(reg1.test(data))
- 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));
- /**
- * 1.安装插件any-rule
- * 2.https://regexper.com/
- * 可视化表达式
- */
- </script>
- </body>
- </html>
|