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

<h2>JavaScript 正则表达式</h2>

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

<script>
var obj = /e/.exec("The best things in life are free!");
document.getElementById("demo").innerHTML =
"Found " + obj[0] + " in position " + obj.index + " in the text: " + obj.input;
</script>

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