6.分组.html 868 B

1234567891011121314151617181920212223242526272829
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. const reg = /(ab)(cd)/;
  11. console.log(reg.test("abcd"));
  12. const str = '2026-05-17';
  13. const reg1 = /^(\d{4})-(\d{2})-(\d{2})$/;
  14. // $1 $2 $3
  15. // 05/17/2026
  16. console.log(str.replace(reg1,'$2/$3/$1'))
  17. // /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/
  18. // 逻辑运算符:| 分支 或
  19. const reg2 = /a|b/;
  20. console.log(reg2.test("a"));
  21. console.log(reg2.test("ab"));
  22. console.log(reg2.test("b"));
  23. console.log(reg2.test("ac"));
  24. console.log(reg2.test("d"));
  25. console.log(reg2.test("fa"));
  26. // https://regexper.com/
  27. </script>
  28. </body>
  29. </html>