blob: f9f1c9a1294a8b11736f130c63ed69a951167841 (
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
|
---
title: RegExp.lastMatch ($&)
slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
original_slug: Web/JavaScript/Referencje/Obiekty/RegExp/lastMatch
---
<div>{{JSRef}} {{non-standard_header}}</div>
<p>Niestandardowa właściwość <strong>lastMatch</strong> jest właściwością statyczną, tylko do odczytu wyrażeń regularnych, który zawiera ostatnie dopasowane znaki. <code>RegExp.$&</code> jest aliasem tej właściwości.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox"><var>RegExp</var>.lastMatch
RegExp['$&']
</pre>
<h2 id="Description">Description</h2>
<p>The <code>lastMatch</code> property is static, it is not a property of an individual regular expression object. Instead, you always use it as <code>RegExp.lastMatch</code> or <code>RegExp['$&'].</code></p>
<p>The value of the <code>lastMatch</code> property is read-only and modified whenever a successful match is made.</p>
<p>You can not use the shorthand alias with the dot property accessor (<code>RegExp.$&</code>), because the parser expects an expression with "&" in that case and a {{jsxref("SyntaxError")}} is thrown. Use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">bracket notation for property access</a>.</p>
<h2 id="Examples">Examples</h2>
<h3 id="Using_lastMatch_and">Using <code>lastMatch</code> and <code>$&</code></h3>
<pre class="brush: js">var re = /hi/g;
re.test('hi there!');
RegExp.lastMatch; // "hi"
RegExp['$&']; // "hi"
</pre>
<h2 id="Specifications">Specifications</h2>
<p>Niestandardowe. Nie jest częścią aktualnej specyfikacji.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("javascript.builtins.RegExp.lastMatch")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li>{{non-standard_inline}} {{jsxref("RegExp.input", "RegExp.input ($_)")}}</li>
<li>{{non-standard_inline}} {{jsxref("RegExp.lastParen", "RegExp.lastParen ($+)")}}</li>
<li>{{non-standard_inline}} {{jsxref("RegExp.leftContext", "RegExp.leftContext ($`)")}}</li>
<li>{{non-standard_inline}} {{jsxref("RegExp.rightContext", "RegExp.rightContext ($')")}}</li>
<li>{{non-standard_inline}} {{jsxref("RegExp.n", "RegExp.$1-$9")}}</li>
</ul>
|