1.认识正则表达式.html 683 B

12345678910111213141516171819202122
  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 名称 = /需要校验的规则/
  11. // test 匹配文本中是否包含要校验的字符 返回布尔值
  12. // replace 替换指定字符
  13. const reg = /西游记/g;
  14. const str = '西游记是四大名著,西游记';
  15. console.log(reg.test("红楼梦是四大名著"));
  16. console.log(reg.exec(str),'exec');
  17. console.log(str.replace(reg,'水浒传'));
  18. console.log(str.match(reg),'match')
  19. </script>
  20. </body>
  21. </html>