aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/regexp/lastindex
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/lastindex
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/lastindex')
-rw-r--r--files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html b/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html
new file mode 100644
index 0000000000..d0b1eceda8
--- /dev/null
+++ b/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html
@@ -0,0 +1,89 @@
+---
+title: RegExp.lastIndex
+slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex
+tags:
+ - JavaScript
+ - Property
+ - Reference
+ - RegExp
+ - Regular Expression
+translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>lastIndex</code></strong> は正規表現インスタンスの読み書き可能なプロパティで、次の一致を開始する位置を指定します。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/regexp-lastindex.html")}}</div>
+
+<div>{{js_property_attributes(1, 0, 0)}}</div>
+
+<h2 id="Syntax" name="Syntax">構文</h2>
+
+<pre class="syntaxbox"><code><var>regExpObj</var>.lastIndex</code></pre>
+
+<h2 id="Description" name="Description">解説</h2>
+
+<p>このプロパティは、正規表現インスタンスがグローバル検索を示すために <code>g</code> フラグを使用した場合、または粘着的検索を示すために <code>y</code> フラグを使用した場合にのみ設定されます。以下の規則が適用されます。</p>
+
+<ul>
+ <li><code>lastIndex</code> が文字列の長さよりも大きければ、 {{jsxref("RegExp.prototype.test()", "test()")}} および {{jsxref("RegExp.prototype.exec()", "exec()")}} は失敗し、<code>lastIndex</code> は 0 にセットされます。</li>
+ <li><code>lastIndex</code> が文字列の長さ以下で、かつ正規表現が空文字列に一致する場合には、正規表現は <code>lastIndex</code> から始まる入力に一致します。</li>
+ <li><code>lastIndex</code> が文字列の長さと等しく、かつ、正規表現が空文字列に一致しない場合、正規表現は入力に一致せず、 <code>lastIndex</code> は 0 にリセットされます。</li>
+ <li>それ以外の場合は、 <code>lastIndex</code> は直近の一致に続く次の位置に設定されます。</li>
+</ul>
+
+<h2 id="Examples" name="Examples">例</h2>
+
+<h3 id="lastIndex_の使用">lastIndex の使用</h3>
+
+<p>例えば、以下の連続した処理を考えてみてください。:</p>
+
+<pre class="brush: js">var re = /(hi)?/g;
+</pre>
+
+<p>空文字列に一致します。</p>
+
+<pre class="brush: js">console.log(re.exec('hi'));
+console.log(re.lastIndex);
+</pre>
+
+<p><code>lastIndex</code> が 2 になり<code>["hi", "hi"]</code> が返ります。</p>
+
+<pre class="brush: js">console.log(re.exec('hi'));
+console.log(re.lastIndex);
+</pre>
+
+<p>ゼロ番目の要素が一致した文字列なので、 <code>["", undefined]</code> という空配列が返ります。この場合、 <code>lastIndex</code> が 2 であったときに (そして 2 のままである)、 <code>hi</code> の長さが 2 であるので、空文字列になります。</p>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-properties-of-regexp-instances', 'RegExp.lastIndex')}}</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.lastIndex")}}</p>
+</div>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li>{{jsxref("RegExp.prototype.ignoreCase")}}</li>
+ <li>{{jsxref("RegExp.prototype.global")}}</li>
+ <li>{{jsxref("RegExp.prototype.multiline")}}</li>
+ <li>{{jsxref("RegExp.prototype.source")}}</li>
+ <li>{{jsxref("RegExp.prototype.sticky")}}</li>
+</ul>