<!DOCTYPE html> <html> <body> <h1>JavaScript 正则表达式</h1> <p>exec() 方法测试(检索)字符串中的匹配项:</p> <p id="demo"></p> <script> let text = "Hello world!"; // 查找 "Hello" let result1 = /Hello/.exec(text); // 查找 "(www.sou-xun.com)" let result2 = /(www.sou-xun.com)/.exec(text); document.getElementById("demo").innerHTML = result1 + "<br>" + result2; </script> </body> </html>