Result Size: 625 x 534
x
 
<!DOCTYPE html>
<html>
<body>
<p>进行全局搜索,并在字符串中测试“Hello”和“BEGTUT”:</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var str = "Hello world!";
  // look for "Hello"
  var patt = /Hello/g;
  var result = patt.test(str);
  // look for "BEGTUT"
  patt2 = /BEGTUT/g;
  result2 = patt2.test(str);
  document.getElementById("demo").innerHTML = result + "<br>" + result2;
}
</script>
</body>
</html>