RegExp.$1〜$9
グループマッチした文字列が$1, $2, $3, $4, $5, $6, $7, $8, $9に格納されます。これは()でグループ化されている必要があります。また、Safari 2では$1〜$9には何も入りません(エラーになります)。
構文
RegExp.$1 RegExp.$2 RegExp.$3 RegExp.$4 RegExp.$5 RegExp.$6 RegExp.$7 RegExp.$8 RegExp.$9
例文
<html>
<head>
<title>RegExp.$1〜$9</title>
</head>
<body>
<script type="text/javascript"><!--
myRE = new RegExp("(\\w+)\\s(\\w+)","g");
txt = "Ruby Python";
result = txt.replace(myRE,"$2 and $1");
document.write("結果"+result.bold()+"<br>");
document.write("$1の内容"+RegExp.$1.bold()+"<br>");
document.write("$2の内容"+RegExp.$2.bold()+"<br>");
// --></script>
</body>
</html>
関連記事
- RegExp
- String.match
- RegExp.rightContext
- RegExp.leftContext
- RegExp.lastParen
- RegExp.lastMatch
- RegExp.lastIndex
- RegExp.index
- RegExp.$n
スポンサーリンク





