aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/regexp/n
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/regexp/n
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/regexp/n')
-rw-r--r--files/ja/web/javascript/reference/global_objects/regexp/n/index.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/regexp/n/index.html b/files/ja/web/javascript/reference/global_objects/regexp/n/index.html
new file mode 100644
index 0000000000..124513909e
--- /dev/null
+++ b/files/ja/web/javascript/reference/global_objects/regexp/n/index.html
@@ -0,0 +1,83 @@
+---
+title: RegExp.$1-$9
+slug: Web/JavaScript/Reference/Global_Objects/RegExp/n
+tags:
+ - JavaScript
+ - Non-standard
+ - Property
+ - Read-only
+ - Reference
+ - RegExp
+ - Regular Expressions
+translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/n
+---
+<div>{{JSRef}}</div>
+
+<p>旧来の <strong>$1, $2, $3, $4, $5, $6, $7, $8, $9</strong> プロパティは、正規表現の静的かつ読み取り専用プロパティで、括弧で括られた部分文字列に一致したものを含みます。</p>
+
+<h2 id="Description" name="Description">解説</h2>
+
+<p>$1, ..., $9 プロパティは静的です。個々の正規表現オブジェクトのプロパティではありません。そのため、常に <code>RegExp.$1</code>, ..., <code>RegExp.$9</code>として使用してください。</p>
+
+<p>これらのプロパティの値は読み取り専用で、一致に成功するたびに変更されます。</p>
+
+<p>括弧で括られた部分文字列の数に制限はありませんが、 <code>RegExp</code> オブジェクトは最初の 9 つの部分文字列しか保持できません。返された配列の添字を使用すると、すべての括弧付き部分文字列にアクセスすることができます。</p>
+
+<p>これらのプロパティは、 {{jsxref("String.replace")}} メソッドの置換テキストで使用することができます。この方法で使用する場合は、これらのプロパティの前に RegExp を付けないでください。以下の例は、これを示しています。正規表現に括弧が含まれていない場合、スクリプトは <code>$n</code> を文字通り解釈します (ここで <code>n</code> は正の整数です)。</p>
+
+<h2 id="Examples" name="Examples">例</h2>
+
+<h3 id="Using_n_with_String.replace" name="Using_n_with_String.replace">$n を String.replace で使用</h3>
+
+<p>次のスクリプトは、 {{jsxref("String")}} インスタンスの {{jsxref("String.prototype.replace()", "replace()")}} メソッドを使用して、名前を <em>first last</em> の形式で一致させ、 <em>last, first</em> の形式で出力します。置換テキストでは、スクリプトは <code>$1</code> と <code>$2</code> を使用して、正規表現パターンで対応する一致する括弧の結果を示しています。</p>
+
+<pre class="brush: js notranslate">var re = /(\w+)\s(\w+)/;
+var str = 'John Smith';
+str.replace(re, '$2, $1'); // "Smith, John"
+RegExp.$1; // "John"
+RegExp.$2; // "Smith"
+</pre>
+
+<h3 id="Using_n_with_RegExp.test" name="Using_n_with_RegExp.test"></h3>
+
+<p>次のスクリプトは、 {{jsxref("RegExp")}} インスタンスの {{jsxref("RegExp.prototype.test()", "test()")}} メソッドを使用して、一般的な文字列で数値を取得しています。</p>
+
+<pre class="brush: js notranslate">var str = 'Test 24';
+var number = /(\d+)/.test(str) ? RegExp.$1 : '0';
+number; // "24"
+</pre>
+
+<p><code>re.test(str)</code> 呼び出しと <code>RegExp.$n</code> プロパティの間で他の正規表現を使用する操作は、副作用がある可能性があることに注意してください。そのため、これらの特殊なプロパティへのアクセスは即座に行うべきで、そうしないと予期せぬ結果になる可能性があります。</p>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('Legacy RegExp features')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
+
+<div>
+<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
+
+<p>{{Compat("javascript.builtins.RegExp.n")}}</p>
+</div>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li>{{jsxref("RegExp.input", "RegExp.input ($_)")}}</li>
+ <li>{{jsxref("RegExp.lastMatch", "RegExp.lastMatch ($&amp;)")}}</li>
+ <li>{{jsxref("RegExp.lastParen", "RegExp.lastParen ($+)")}}</li>
+ <li>{{jsxref("RegExp.leftContext", "RegExp.leftContext ($`)")}}</li>
+ <li>{{jsxref("RegExp.rightContext", "RegExp.rightContext ($')")}}</li>
+</ul>