aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html98
1 files changed, 98 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html
new file mode 100644
index 0000000000..71a49daf44
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastmatch/index.html
@@ -0,0 +1,98 @@
+---
+title: RegExp.lastMatch ($&)
+slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch
+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="语法">语法</h2>
+
+<pre class="syntaxbox"><var>RegExp</var>.lastMatch
+RegExp['$&amp;']
+</pre>
+
+<h2 id="描述">描述</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="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">方括号符号</a>来访问属性。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="使用_lastMatch_和">使用 <code>lastMatch</code> 和 <code>$&amp;</code></h3>
+
+<pre class="brush: js">var re = /hi/g;
+re.test('hi there!');
+RegExp.lastMatch; // "hi"
+RegExp['$&amp;']; // "hi"
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<p>非标准。并不是任何现行规范的一部分。</p>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="另见">另见</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>