aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/regexp/lastmatch/index.html
blob: 73dc55ee32f102828c6de9942332b742c822efd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: RegExp.lastMatch ($&)
slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
tags:
  - JavaScript
  - Non-standard
  - Property
  - Read-only
  - Reference
  - RegExp
  - Regular Expressions
translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
---
<div>{{JSRef}} {{non-standard_header}}</div>

<p>標準外の <strong>lastMatch</strong> プロパティは、最後に一致した文字列を含む正規表現の静的で読み取り専用のプロパティです。 <code>RegExp.$&amp;</code> はこのプロパティに対するエイリアスです。</p>

<h2 id="Description" name="Description">解説</h2>

<p><code>lastMatch</code> プロパティは静的プロパティです。個々の正規表現オブジェクトのプロパティではありません。そのかわりに、常に、<code>RegExp.lastMatch</code>または<code>RegExp['$&amp;'].</code>として使用してください。</p>

<p><code>lastMatch</code> プロパティの値は、読み取り専用で、一致に成功するたびに変更されます。</p>

<p>ドットプロパティアクセサー (<code>RegExp.$&amp;</code>) で短縮エイリアスを使用することはできません。その場合、パーサーは "&amp;" という表現を期待して {{jsxref("SyntaxError")}} が発生します。<a href="/docs/Web/JavaScript/Reference/Operators/Property_Accessors">プロパティへのアクセスにはブラケット表記法</a>を使用してください。</p>

<h2 id="Examples" name="Examples"></h2>

<h3 id="Using_lastMatch_and" name="Using_lastMatch_and">lastMatch と $&amp; の使用</h3>

<pre class="brush: js notranslate">var re = /hi/g;
re.test('hi there!');
RegExp.lastMatch; // "hi"
RegExp['$&amp;'];     // "hi"
</pre>

<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>
<p>{{Compat("javascript.builtins.RegExp.lastMatch")}}</p>
</div>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{jsxref("RegExp.input", "RegExp.input ($_)")}}</li>
 <li>{{jsxref("RegExp.lastParen", "RegExp.lastParen ($+)")}}</li>
 <li>{{jsxref("RegExp.leftContext", "RegExp.leftContext ($`)")}}</li>
 <li>{{jsxref("RegExp.rightContext", "RegExp.rightContext ($')")}}</li>
 <li>{{jsxref("RegExp.n", "RegExp.$1-$9")}}</li>
</ul>