123456789101112131415161718 |
- <!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 str = '2025-09-18';
- // 09/18/2025
- const reg = /^(\d{4})-(\d{2})-(\d{2})$/;
- console.log(reg.test(str))
- console.log(str.replace(reg,'$2/$3/$1'))
- // 分支结构: |
- </script>
- </body>
- </html>
|