12345678910111213141516171819202122232425262728 |
- <!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 = /西游记/g;
- // 1.test()
- const result = reg.test("这是一本西游ddd记");
- console.log(result);
- // 2.exec()
- const result1 = reg.exec("这是一本西游记,西游记");
- console.log(result1);
- // 3.replace()
- var str = '一段西游记的文字';
- const result2 = str.replace(reg,'红楼梦');
- console.log(result2);
- // 4.match()
- var str1 = '一本书西游记,我也爱看西游记,西游记呀';
- const result3 = str1.match(reg);
- console.log(result3);
- </script>
- </body>
- </html>
|