



RegExpオブジェクトのlastMatchプロパティは、最後にマッチした文字列を返します。
RegExpオブジェクトのlastMatchプロパティは、すでにウェブ標準から削除されています。
RegExp[‘$&’]と書いても同じ結果を得られるので、後者の書式で記述しても良いでしょう。
<script>
var sample = /Ball/g;
sample.test("BaseBall VolleyBall BasketBall");
document.write("<div>最後にマッチした文字列1: " + RegExp.lastMatch + "</div>");
document.write("<div>最後にマッチした文字列2: " + RegExp['$&'] + "</div>");
document.write("<div>最新のマッチした文字列の左側の文字列1: " + RegExp.leftContext + "</div>");
document.write("<div>最新のマッチした文字列の左側の文字列2: " + RegExp['$`'] + "</div>");
document.write("<div>最新のマッチした文字列の右側の文字列1: " + RegExp.rightContext + "</div>");
document.write("<div>最新のマッチした文字列の右側の文字列2: " + RegExp["$'"] + "</div>");
</script>
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);
document.write(“
“);