| 1234567891011121314151617181920212223242526272829 |
- <!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("abcd"));
- const str = '2026-05-17';
- const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/;
- // $1 $2 $3
- // 05/17/2026
- console.log(str.replace(reg1,'$2/$3/$1'))
- // /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/
- // 逻辑运算符:| 分支 或
- const reg2 = /a|b/;
- console.log(reg2.test("a"));
- console.log(reg2.test("ab"));
- console.log(reg2.test("b"));
- console.log(reg2.test("ac"));
- console.log(reg2.test("d"));
- console.log(reg2.test("fa"));
- // https://regexper.com/
- </script>
- </body>
- </html>
|