代码示例:(标识:jsck_match_regexp_1)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript 字符串</h1>

<h2>match() 方法</h2>

<p>match() 在字符串中搜索匹配项。</p>

<p>检索 "ain":</p>

<p id="demo"></p>

<script>
let text = "The rain in SPAIN stays mainly in the plain";
let result = text.match("ain");
 
document.getElementById("demo").innerHTML = result;
</script>

</body>
</html>
运行结果: