语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -2,7 +2,7 @@
<div></div>
<p><em>正则表达式</em>匹配<em>字符串</em>时,<strong><code>[@@match]()</code></strong>方法用于获取匹配结果。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>regexp</var>[Symbol.match](str)</pre>
<pre><code class="language-javascript"><var>regexp</var>[Symbol.match](str)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -12,21 +12,21 @@
<p>match 方法会返回一个数组它包括整个匹配结果和通过捕获组匹配到的结果如果没有匹配到则返回null</p>
<h2 id="描述">描述</h2>
<p>这个方法在 <a href="Reference/Global_Objects/String/match" title="当一个字符串与一个正则表达式匹配时 match()方法检索匹配项。"><code>String.prototype.match()</code></a> 的内部调用。例如,下面的两个方法返回相同结果。</p>
<pre class="brush: js">'abc'.match(/a/);
<pre><code class="language-javascript">'abc'.match(/a/);
/a/[Symbol.match]('abc');</pre>
/a/[Symbol.match]('abc');</code></pre>
<p>这个方法为自定义 <code>RegExp</code> 子类中的匹配行为而存在。</p>
<h2 id="示例">示例</h2>
<h3 id="直接调用">直接调用</h3>
<p>这个方法的使用方式和 <a href="Reference/Global_Objects/String/match" title="当一个字符串与一个正则表达式匹配时 match()方法检索匹配项。"><code>String.prototype.match()</code></a> 相同,不同之处是 <code>this</code> 和参数顺序。</p>
<pre class="brush: js">var re = /[0-9]+/g;
<pre><code class="language-javascript">var re = /[0-9]+/g;
var str = '2016-01-02';
var result = re[Symbol.match](str);
console.log(result); // ["2016", "01", "02"]
</pre>
</code></pre>
<h3 id="在子类中使用match">在子类中使用<code>@@match</code></h3>
<p><a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 的子类可以覆写 <code>[@@match]()</code>方法来修改默认行为。</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
[Symbol.match](str) {
var result = RegExp.prototype[Symbol.match].call(this, str);
if (!result) return null;
@@ -44,7 +44,7 @@ var result = str.match(re); // String.prototype.match calls re[@@match].
console.log(result.group(1)); // 2016
console.log(result.group(2)); // 01
console.log(result.group(3)); // 02
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,7 +4,7 @@
<div>{{EmbedInteractiveExample("pages/js/regexp-prototype-@@matchall.html")}}</div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>regexp</var>[Symbol.matchAll](<var>str</var>)</pre>
<pre><code class="language-javascript"><var>regexp</var>[Symbol.matchAll](<var>str</var>)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -14,23 +14,23 @@
<p>一个<a href="Guide/Iterators_and_Generators">迭代器</a></p>
<h2 id="描述">描述</h2>
<p>本方法在<a href="Reference/Global_Objects/String/matchAll" title="matchAll() 方法返回一个包含所有匹配正则表达式及分组捕获结果的迭代器。"><code>String.prototype.matchAll()</code></a>中被内部调用。例如,以下两个示例返回相同的结果。</p>
<pre class="brush: js">'abc'.matchAll(/a/);
<pre><code class="language-javascript">'abc'.matchAll(/a/);
/a/[Symbol.matchAll]('abc');</pre>
/a/[Symbol.matchAll]('abc');</code></pre>
<p>本方法用于自定义<code>RegExp</code>子类中的匹配行为。</p>
<h2 id="示例">示例</h2>
<h3 id="直接调用">直接调用</h3>
<p>本方法的使用方法几乎与<a href="Reference/Global_Objects/String/matchAll" title="matchAll() 方法返回一个包含所有匹配正则表达式及分组捕获结果的迭代器。"><code>String.prototype.matchAll()</code></a>相同,除了<code>this</code> 的不同以及参数顺序的的差异。</p>
<pre class="brush: js">var re = /[0-9]+/g;
<pre><code class="language-javascript">var re = /[0-9]+/g;
var str = '2016-01-02';
var result = re[Symbol.matchAll](str);
console.log(<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="cm-variable">Array</span>.<span class="cm-property">from</span>(<span class="cm-variable">result</span>, <span class="cm-def">x</span> <span class="cm-operator">=&gt;</span> <span class="cm-variable-2">x</span>[<span class="cm-number">0</span>])</span></span></span>);
// ["2016", "01", "02"]
</pre>
</code></pre>
<h3 id="在子类中使用matchAll">在子类中使用<code>@@matchAll</code></h3>
<p><a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>的子类可以重写<code>[@@matchAll]()</code>方法来修改默认行为。例如,返回一个<a href="Reference/Array" title="REDIRECT Array"><code>Array</code></a>而不是<a href="Guide/Iterators_and_Generators">iterator</a>:</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
[Symbol.matchAll](str) {
var result = RegExp.prototype[Symbol.matchAll].call(this, str);
if (!result) {
@@ -46,7 +46,7 @@ var str = '2016-01-02|2019-03-07';
var result = str.matchAll(re);
console.log(result[0]); // [ "2016-01-02", "2016", "01", "02" ]
console.log(result[1]); // [ "2019-03-07", "2019", "03", "07" ]
</pre>
</code></pre>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div>
<p></p><div class="bc-data"><a class="bc-github-link external" href="https://github.com/mdn/browser-compat-data" rel="noopener">Update compatibility data on GitHub</a><table class="bc-table bc-table-js"><thead><tr class="bc-platforms"><td></td><th class="bc-platform-desktop" colspan="6"><span>Desktop</span></th><th class="bc-platform-mobile" colspan="7"><span>Mobile</span></th><th class="bc-platform-server" colspan="1"><span>Server</span></th></tr><tr class="bc-browsers"><td></td><th class="bc-browser-chrome"><span class="bc-head-txt-label bc-head-icon-chrome">Chrome</span></th><th class="bc-browser-edge"><span class="bc-head-txt-label bc-head-icon-edge">Edge</span></th><th class="bc-browser-firefox"><span class="bc-head-txt-label bc-head-icon-firefox">Firefox</span></th><th class="bc-browser-ie"><span class="bc-head-txt-label bc-head-icon-ie">Internet Explorer</span></th><th class="bc-browser-opera"><span class="bc-head-txt-label bc-head-icon-opera">Opera</span></th><th class="bc-browser-safari"><span class="bc-head-txt-label bc-head-icon-safari">Safari</span></th><th class="bc-browser-webview_android"><span class="bc-head-txt-label bc-head-icon-webview_android">Android webview</span></th><th class="bc-browser-chrome_android"><span class="bc-head-txt-label bc-head-icon-chrome_android">Chrome for Android</span></th><th class="bc-browser-edge_mobile"><span class="bc-head-txt-label bc-head-icon-edge_mobile">Edge Mobile</span></th><th class="bc-browser-firefox_android"><span class="bc-head-txt-label bc-head-icon-firefox_android">Firefox for Android</span></th><th class="bc-browser-opera_android"><span class="bc-head-txt-label bc-head-icon-opera_android">Opera for Android</span></th><th class="bc-browser-safari_ios"><span class="bc-head-txt-label bc-head-icon-safari_ios">Safari on iOS</span></th><th class="bc-browser-samsunginternet_android"><span class="bc-head-txt-label bc-head-icon-samsunginternet_android">Samsung Internet</span></th><th class="bc-browser-nodejs"><span class="bc-head-txt-label bc-head-icon-nodejs">Node.js</span></th></tr></thead><tbody><tr><th scope="row"><code>@@matchAll</code></th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">

View File

@@ -3,7 +3,7 @@
<p> <strong><code>[@@replace]()</code></strong> 方法会在一个字符串中用给定的替换器,替换所有符合正则模式的匹配项,并返回替换后的新字符串结果。用来替换的参数可以是一个字符串或是一个针对每次匹配的回调函数。</p>
<p><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/regexp-prototype-@@replace.html" width="100%"></iframe></p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>regexp</var>[Symbol.replace](str, <var>newSubStr</var>|<var>function</var>)</pre>
<pre><code class="language-javascript"><var>regexp</var>[Symbol.replace](str, <var>newSubStr</var>|<var>function</var>)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -17,22 +17,22 @@
<p>用替换器替换相应匹配项后的新字符串。</p>
<h2 id="描述">描述</h2>
<p>如果匹配模式也是<a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>对象,这个方法在 <a href="Reference/Global_Objects/String/replace" title="replace() 方法返回一个由替换值replacement替换一些或所有匹配的模式pattern后的新字符串。模式可以是一个字符串或者一个正则表达式替换值可以是一个字符串或者一个每次匹配都要调用的函数。"><code>String.prototype.replace()</code></a> 的内部调用。例如,下面的两个方法返回相同结果。</p>
<pre class="brush: js">'abc'.replace(/a/, 'A');
<pre><code class="language-javascript">'abc'.replace(/a/, 'A');
/a/[Symbol.replace]('abc', 'A');</pre>
/a/[Symbol.replace]('abc', 'A');</code></pre>
<p>该方法是为了在RegExp子类中自定义匹配的替换模式。</p>
<p>如果匹配模式不是一个<a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 对象, <a href="Reference/Global_Objects/String/replace" title="replace() 方法返回一个由替换值replacement替换一些或所有匹配的模式pattern后的新字符串。模式可以是一个字符串或者一个正则表达式替换值可以是一个字符串或者一个每次匹配都要调用的函数。"><code>String.prototype.replace()</code></a> 就不会调用该方法,也不会创建一个 <a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>对象。</p>
<h2 id="示例">示例</h2>
<h3 id="直接调用">直接调用</h3>
<p>这个方法基本可以和 <a href="Reference/Global_Objects/String/replace" title="replace() 方法返回一个由替换值replacement替换一些或所有匹配的模式pattern后的新字符串。模式可以是一个字符串或者一个正则表达式替换值可以是一个字符串或者一个每次匹配都要调用的函数。"><code>String.prototype.replace()</code></a> 一样使用, 不同之处是 <code>this</code> 和参数顺序。</p>
<pre class="brush: js">var re = /-/g;
<pre><code class="language-javascript">var re = /-/g;
var str = '2016-01-01';
var newstr = re[Symbol.replace](str, '.');
console.log(newstr); // 2016.01.01
</pre>
</code></pre>
<h3 id="在子类中使用replace">在子类中使用@@replace</h3>
<p><a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 的子类可以覆写 <code>[@@replace]()</code>方法来修改默认行为。</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
constructor(pattern, flags, count) {
super(pattern, flags);
this.count = count;
@@ -50,7 +50,7 @@ console.log(newstr); // 2016.01.01
var re = new MyRegExp('\\d', '', 3);
var str = '01234567';
var newstr = str.replace(re, '#'); // String.prototype.replace calls re[@@replace].
console.log(newstr); // ###34567</pre>
console.log(newstr); // ###34567</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -2,7 +2,7 @@
<div></div>
<p><strong><code>[@@search]()</code></strong> 方法执行了一个在给定字符串中的一个搜索以取得匹配正则模式的项。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>regexp</var>[Symbol.search](str)</pre>
<pre><code class="language-javascript"><var>regexp</var>[Symbol.search](str)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -15,21 +15,21 @@
</dl>
<h2 id="描述">描述</h2>
<p>这个方法在 <a href="Reference/Global_Objects/String/search" title="search() 方法执行正则表达式和 String对象之间的一个搜索匹配。"><code>String.prototype.search()</code></a> 的内部调用。例如,下面的两个方法返回相同结果。</p>
<pre class="brush: js">'abc'.search(/a/);
<pre><code class="language-javascript">'abc'.search(/a/);
/a/[Symbol.search]('abc');</pre>
/a/[Symbol.search]('abc');</code></pre>
<p>这个方法为自定义 <code>RegExp</code> 子类中的匹配行为而存在。</p>
<h2 id="示例">示例</h2>
<h3 id="直接调用">直接调用</h3>
<p>这个方法的使用方式和 <a href="Reference/Global_Objects/String/search" title="search() 方法执行正则表达式和 String对象之间的一个搜索匹配。"><code>String.prototype.search()</code></a> 相同,不同之处是 <code>this</code> 和参数顺序。</p>
<pre class="brush: js">var re = /-/g;
<pre><code class="language-javascript">var re = /-/g;
var str = '2016-01-02';
var result = re[Symbol.search](str);
console.log(result); // 4
</pre>
</code></pre>
<h3 id="在子类中使用search">在子类中使用<code>@@search</code></h3>
<p>{jsxref("RegExp")}} 的子类可以覆写 <code>[@@search]()</code>方法来修改默认行为。</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
constructor(str) {
super(str)
this.pattern = str;
@@ -43,7 +43,7 @@ var re = new MyRegExp('a+b');
var str = 'ab a+b';
var result = str.search(re); // String.prototype.search calls re[@@search].
console.log(result); // 3
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -2,18 +2,18 @@
<div></div>
<p><code><strong>RegExp[@@species]</strong></code> 访问器属性返回<code>RegExp</code> 的构造器。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">RegExp[Symbol.species]
</pre>
<pre><code class="language-javascript">RegExp[Symbol.species]
</code></pre>
<h2 id="描述">描述</h2>
<p><code>species</code> 访问器属性返回 <code>RegExp</code> 对象的默认构造器。子类构造器可能会覆盖它,来修改构造器的指派。</p>
<h2 id="示例">示例</h2>
<p><code>species</code>属性返回默认构造器函数,它是用于<code>RegExp</code> 对象的<code>RegExp</code>构造器:</p>
<pre class="brush: js">RegExp[Symbol.species]; // 函数 RegExp()</pre>
<pre><code class="language-javascript">RegExp[Symbol.species]; // 函数 RegExp()</code></pre>
<p>在派生的正则类(也就是你自定义的正则类 <code>MyRegExp</code>)中,<code>MyRegExp</code> 的 species 是 <code>MyRegExp</code> 构造器。但是,你可能希望覆盖它,以便在你的派生类方法中,返回 <code>RegExp</code> 父类对象:</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
// 将 MyRegExp species 覆盖为 RegExp 父类构造器
static get [Symbol.species]() { return RegExp; }
}</pre>
}</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -2,7 +2,7 @@
<div></div>
<p><strong><code>[@@split]()</code></strong> 方法切割 <a href="Reference/String" title="此页面仍未被本地化, 期待您的翻译!"><code>String</code></a> 对象为一个其子字符串的数组 。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>regexp</var>[Symbol.split](str[, <var>limit</var>])</pre>
<pre><code class="language-javascript"><var>regexp</var>[Symbol.split](str[, <var>limit</var>])</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -16,21 +16,21 @@
<p>包含其子字符串的<a href="Reference/Array" title="REDIRECT Array"><code>Array</code></a></p>
<h2 id="描述">描述</h2>
<p>如果切割器是一个<a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>对象,这个方法就将在 <a href="Reference/Global_Objects/String/split" title="split() 方法使用指定的分隔符字符串将一个String对象分割成字符串数组以将字符串分隔为子字符串以确定每个拆分的位置。"><code>String.prototype.split()</code></a> 的内部调用。例如,下面的两个方法返回相同结果。</p>
<pre class="brush: js">'a-b-c'.split(/-/);
<pre><code class="language-javascript">'a-b-c'.split(/-/);
/-/[Symbol.split]('a-b-c');</pre>
/-/[Symbol.split]('a-b-c');</code></pre>
<p>这个方法为自定义 <code>RegExp</code> 子类中的匹配行为而存在。</p>
<p>如果str参数不是一个<a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 对象, <a href="Reference/Global_Objects/String/split" title="split() 方法使用指定的分隔符字符串将一个String对象分割成字符串数组以将字符串分隔为子字符串以确定每个拆分的位置。"><code>String.prototype.split()</code></a> 就不会调用该方法,也不会创建一个 <a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 对象。示例</p>
<h3 id="直接调用">直接调用</h3>
<p>这个方法的使用方式和 <a href="Reference/Global_Objects/String/split" title="split() 方法使用指定的分隔符字符串将一个String对象分割成字符串数组以将字符串分隔为子字符串以确定每个拆分的位置。"><code>String.prototype.split()</code></a> 相同,不同之处是 <code>this</code> 和参数顺序。</p>
<pre class="brush: js">var re = /-/g;
<pre><code class="language-javascript">var re = /-/g;
var str = '2016-01-02';
var result = re[Symbol.split](str);
console.log(result); // ["2016", "01", "02"]
</pre>
</code></pre>
<h3 id="在子类中使用_split">在子类中使用 <code>@@split</code></h3>
<p><a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a> 的子类可以覆写 <code>[@@split]()</code>方法来修改默认行为。</p>
<pre class="brush: js">class MyRegExp extends RegExp {
<pre><code class="language-javascript">class MyRegExp extends RegExp {
[Symbol.split](str, limit) {
var result = RegExp.prototype[Symbol.split].call(this, str, limit);
return result.map(x =&gt; "(" + x + ")");
@@ -41,7 +41,7 @@ var re = new MyRegExp('-');
var str = '2016-01-02';
var result = str.split(re); // String.prototype.split calls re[@@split].
console.log(result); // ["(2016)", "(01)", "(02)"]
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,7 +4,7 @@
</div></div>
<p><code>已废弃的<strong>compile</strong></code><strong><code>()</code></strong> 方法被用于在脚本执行过程中(重新)编译正则表达式。与<code>RegExp</code>构造函数基本一样。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>regexObj</var>.compile(<var>pattern, flags</var>)</code></pre>
<pre><code class="language-javascript"><code><var>regexObj</var>.compile(<var>pattern, flags</var>)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>pattern</code></dt>
@@ -29,9 +29,9 @@
<h2 id="示例">示例</h2>
<h3 id="使用compile()"><code>使用compile()</code></h3>
<p>以下展示如何用新模式和新标志来重新编译正则表达式。</p>
<pre class="brush: js">var regexObj = new RegExp("foo", "gi");
<pre><code class="language-javascript">var regexObj = new RegExp("foo", "gi");
regexObj.compile("new foo", "g");
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -5,7 +5,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/regexp-prototype-exec.html" width="100%"></iframe></div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><var>regexObj</var>.exec(<var>str</var>)</pre>
<pre><code class="language-javascript"><var>regexObj</var>.exec(<var>str</var>)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -16,12 +16,12 @@
<p>如果匹配失败exec() 方法返回 <a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a></p>
<h2 id="描述">描述</h2>
<p>考虑以下示例:</p>
<pre class="brush: js">// Match "quick brown" followed by "jumps", ignoring characters in between
<pre><code class="language-javascript">// Match "quick brown" followed by "jumps", ignoring characters in between
// Remember "brown" and "jumps"
// Ignore case
var re = /quick\s(brown).+?(jumps)/ig;
var result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog');
</pre>
</code></pre>
<p>下表列出这个脚本的返回值:</p>
<table class="fullwidth-table">
<tbody>
@@ -86,7 +86,7 @@ var result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog');
<h2 id="示例">示例</h2>
<h3 id="查找所有匹配">查找所有匹配</h3>
<p>当正则表达式使用 "<code>g</code>" 标志时,可以多次执行 <code>exec</code> 方法来查找同一个字符串中的成功匹配。当你这样做时,查找将从正则表达式的 <a href="Reference/Global_Objects/RegExp/lastIndex" title="lastIndex 是正则表达式的一个可读可写的整型属性用来指定下一次匹配的起始索引。"><code>lastIndex</code></a> 属性指定的位置开始。(<a href="Reference/Global_Objects/RegExp/test" title="test() 方法执行一个检索,用来查看正则表达式与指定的字符串是否匹配。返回 true 或 false。"><code>test()</code></a> 也会更新 <code>lastIndex</code> 属性)。例如,你使用下面的脚本:</p>
<pre class="brush: js">var myRe = /ab*/g;
<pre><code class="language-javascript">var myRe = /ab*/g;
var str = 'abbcdefabh';
var myArray;
while ((myArray = myRe.exec(str)) !== null) {
@@ -94,17 +94,17 @@ while ((myArray = myRe.exec(str)) !== null) {
msg += 'Next match starts at ' + myRe.lastIndex;
console.log(msg);
}
</pre>
</code></pre>
<p>脚本运行结果如下:</p>
<pre>Found abb. Next match starts at 3
Found ab. Next match starts at 9
</pre>
</code></pre>
<p>注意:不要把正则表达式字面量(或者<a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>构造器)放在 <code>while</code> 条件表达式里。由于每次迭代时 <a href="Reference/Global_Objects/RegExp/lastIndex" title="lastIndex 是正则表达式的一个可读可写的整型属性用来指定下一次匹配的起始索引。"><code>lastIndex</code></a>的属性都被重置,如果匹配,将会造成一个死循环。并且要确保使用了'g'标记来进行全局的匹配,否则同样会造成死循环。</p>
<h3 id="结合_RegExp_字面量使用_exec()">结合 <code>RegExp</code> 字面量使用 <code>exec()</code></h3>
<p>你也可以直接使用 <code>exec()</code> 而不是创建一个 <a href="Reference/RegExp" title="此页面仍未被本地化, 期待您的翻译!"><code>RegExp</code></a>  对象:</p>
<pre class="brush: js">var matches = /(hello \S+)/.exec('This is a hello world!');
<pre><code class="language-javascript">var matches = /(hello \S+)/.exec('This is a hello world!');
console.log(matches[1]);
</pre>
</code></pre>
<p>运行上面的代码,控制台会输出"hello world!" 字符串。</p>
<h2 id="规范">规范</h2>
<table class="standard-table">

View File

@@ -26,11 +26,11 @@
<p><code>flags</code>属性中的标志以字典序排序(从左到右,即<code>"gimuy"</code>)。</p>
<h2 id="示例">示例</h2>
<h3 id="使用flags">使用<code>flags</code></h3>
<pre class="brush: js">/foo/ig.flags; // "gi"
<pre><code class="language-javascript">/foo/ig.flags; // "gi"
/bar/myu.flags; // "muy"
</pre>
</code></pre>
<h2 id="Polyfill">Polyfill</h2>
<pre class="brush: js">if (RegExp.prototype.flags === undefined) {
<pre><code class="language-javascript">if (RegExp.prototype.flags === undefined) {
Object.defineProperty(RegExp.prototype, 'flags', {
configurable: true,
get: function() {
@@ -38,7 +38,7 @@
}
});
}
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -30,10 +30,10 @@
<p>你无法直接更改此属性。</p>
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_MIN_VALUE" name="Example:_Using_MIN_VALUE">例子:使用 <code>global</code></h3>
<pre class="brush:js">var regex = new RegExp("foo", "g")
<pre><code class="language-js">var regex = new RegExp("foo", "g")
console.log(regex.global) // true
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -30,10 +30,10 @@
<p>你无法直接更改此属性。</p>
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_MIN_VALUE" name="Example:_Using_MIN_VALUE">例子:使用 <code>ignoreCase</code></h3>
<pre class="brush:js">var regex = new RegExp("foo", "i")
<pre><code class="language-js">var regex = new RegExp("foo", "i")
console.log(regex.ignoreCase) // true
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -5,22 +5,22 @@
</div></div>
<p><strong><code>input</code> </strong>非标准属性是正则表达式静态属性,含有正则表达式所匹配的字符串。<code>RegExp.$_</code>是这个属性的别名。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>RegExp</var>.input
<pre><code class="language-javascript"><var>RegExp</var>.input
RegExp.$_
</pre>
</code></pre>
<h2 id="描述">描述</h2>
<p><code>input</code> 属性是静态的,并不是正则表达式独立对象的属性。反之,你应始终将其使用为 <code>RegExp.input</code> 或者 <code>RegExp.$_。</code></p>
<p>当正则表达式上搜索的字符串发生改变,并且字符串匹配时,<code><strong>input</strong></code> 属性的值会修改。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_input_和__">使用 <code>input</code><code>$_</code></h3>
<pre class="brush: js">var re = /hi/g;
<pre><code class="language-javascript">var re = /hi/g;
re.test('hi there!');
RegExp.input; // "hi there!"
re.test('foo'); // 新测试,不匹配
RegExp.$_; // "hi there!"
re.test('hi world!'); // 新测试,匹配
RegExp.$_; // "hi world!"
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>

View File

@@ -26,7 +26,7 @@
</tbody>
</table></div>
<h2 id="语法" style="margin-bottom: 20px; line-height: 30px;">语法</h2>
<pre class="syntaxbox language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(212, 221, 228, 0.498039);"><var>lastIndex</var> = <var>regExpObj</var>.lastIndex;</pre>
<pre><code class="language-html" style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; direction: ltr; white-space: normal; text-shadow: none; background-color: rgba(212, 221, 228, 0.498039);"><var>lastIndex</var> = <var>regExpObj</var>.lastIndex;</code></pre>
<h2 id="Description" name="Description" style="margin-bottom: 20px; line-height: 30px;">描述</h2>
<p>只有正则表达式使用了表示全局检索的 "<code>g</code>" 标志时,该属性才会起作用。此时应用下面的规则:</p>
<ul>
@@ -37,19 +37,19 @@
</ul>
<h2 id="示例" style="margin-bottom: 20px; line-height: 30px;">示例</h2>
<p>考虑下面的语句:</p>
<pre class="brush: js">var re = /(hi)?/g;</pre>
<pre><code class="language-javascript">var re = /(hi)?/g;</code></pre>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: 0px 0px;">
 </div>
<p>匹配空字符串</p>
<pre class="brush: js">console.log(re.exec("hi"));
console.log(re.lastIndex);</pre>
<pre><code class="language-javascript">console.log(re.exec("hi"));
console.log(re.lastIndex);</code></pre>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: 0px 0px;">
 </div>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 19px; background: 0px 0px;">
 </div>
<p>返回 <code>["hi", "hi"]</code> <code>lastIndex</code> 等于 2。</p>
<pre class="brush: js">console.log(re.exec("hi"));
console.log(re.lastIndex);</pre>
<pre><code class="language-javascript">console.log(re.exec("hi"));
console.log(re.lastIndex);</code></pre>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 0px; background: 0px 0px;">
 </div>
<div class="line-number" style="margin-top: 1em; position: absolute; left: 0px; right: 0px; line-height: inherit; top: 19px; background: 0px 0px;">

View File

@@ -5,20 +5,20 @@
</div></div>
<p><strong>lastMatch </strong>非标准属性是正则表达式的静态和只读属性,含有最后匹配到的字符串。<code>RegExp.$&amp;</code> 是这个属性的别名。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>RegExp</var>.lastMatch
<pre><code class="language-javascript"><var>RegExp</var>.lastMatch
RegExp['$&amp;']
</pre>
</code></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;" 看做表达式,并抛出 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a> 。使用 <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;
<pre><code class="language-javascript">var re = /hi/g;
re.test('hi there!');
RegExp.lastMatch; // "hi"
RegExp['$&amp;']; // "hi"
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>

View File

@@ -5,20 +5,20 @@
</div></div>
<p><strong>lastParen </strong>非标准属性是正则表达式的静态和只读属性,包含匹配到的最后一个子串(如果存在)。<code>RegExp.$+</code>是这一属性的别名。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>RegExp</var>.lastParen
<pre><code class="language-javascript"><var>RegExp</var>.lastParen
RegExp['$+']
</pre>
</code></pre>
<h2 id="描述">描述</h2>
<p><code>lastParen</code> 属性是静态的,不是正则表达式独立对象的属性。反之,你应始终将其使用为 <code>RegExp.lastParen</code> 或者 <code>RegExp['$+']</code></p>
<p><code>lastParen</code> 属性的值是只读的,并且会在匹配成功时修改。</p>
<p>你不能使用属性访问器(<code>RegExp.$+</code>)来使用简写的别名,因为解析器在这里会将 "+" 看做表达式,并抛出 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a> 。使用 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">方括号符号</a>来访问属性。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_lastParen_和">使用 <code>lastParen</code><code>$+</code></h3>
<pre class="brush: js">var re = /(hi)/g;
<pre><code class="language-javascript">var re = /(hi)/g;
re.test('hi there!');
RegExp.lastParen; // "hi"
RegExp['$+']; // "hi"
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>

View File

@@ -5,20 +5,20 @@
</div></div>
<p><strong>leftContext </strong>非标准属性是正则表达式的静态和只读属性,含有最新匹配的左侧子串。 <code>RegExp.$`</code> 是这个属性的别名。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><var>RegExp</var>.leftContext
<pre><code class="language-javascript"><var>RegExp</var>.leftContext
RegExp['$`']
</pre>
</code></pre>
<h2 id="描述">描述</h2>
<p><code>leftContext</code> 属性是静态的,不是正则表达式独立对象的属性。反之,你应始终将其使用为 <code>RegExp.leftContext</code> 或者 <code>RegExp['$`']</code></p>
<p><code>leftContext</code> 属性的值是只读的,并且会在匹配成功时修改。</p>
<p>你不能使用属性访问器(<code>RegExp.$`</code>)来使用简写的别名,因为解析器在这里会将其看做模板字符串的开始,并抛出 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a> 。使用 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">方括号符号</a>来访问属性。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_leftContext_和">使用 <code>leftContext</code><code>$`</code></h3>
<pre class="brush: js">var re = /world/g;
<pre><code class="language-javascript">var re = /world/g;
re.test('hello world!');
RegExp.leftContext; // "hello "
RegExp['$`']; // "hello "
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>

View File

@@ -30,10 +30,10 @@
<p>你无法直接更改此属性。</p>
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_MIN_VALUE" name="Example:_Using_MIN_VALUE">例子:使用 <code>multiline</code></h3>
<pre class="brush:js">var regex = new RegExp("foo", "m")
<pre><code class="language-js">var regex = new RegExp("foo", "m")
console.log(regex.multiline) // true
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -5,7 +5,7 @@
</div></div>
<p>非标准<strong>$1, $2, $3, $4, $5, $6, $7, $8, $9 </strong>属性是包含括号子串匹配的正则表达式的静态和只读属性。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>RegExp</var>.$1
<pre><code class="language-javascript"><code><var>RegExp</var>.$1
RegExp.$2</code>
RegExp.$3
RegExp.$4
@@ -14,7 +14,7 @@ RegExp.$6
RegExp.$7
RegExp.$8
RegExp.$9
</pre>
</code></pre>
<h2 id="描述">描述</h2>
<p>$1, ..., $9 属性是静态的, 他不是独立的的正则表达式属性. 所以, 我们总是像这样子使用他们<code>RegExp.$1</code>, ..., <code>RegExp.$9</code>.</p>
<p>属性的值是只读的而且只有在正确匹配的情况下才会改变.</p>
@@ -23,12 +23,12 @@ RegExp.$9
<h2 id="例子">例子</h2>
<h3 id="n_在_String.replace中的应用"><code>$n</code> 在 <code>String.replace中的应用</code></h3>
<p>以下脚本用 <a href="Reference/Global_Objects/String/replace" title="replace() 方法返回一个由替换值替换一些或所有匹配的模式后的新字符串。模式可以是一个字符串或者一个正则表达式, 替换值可以是一个字符串或者一个每次匹配都要调用的函数。"><code>replace()</code></a> 方法去匹配一个first last格式的 name<a href="Reference/String" title="此页面仍未被本地化, 期待您的翻译!"><code>String</code></a> 实例 输出last first格式. 在替换文本里, 脚本用 <code>$1</code> 和 <code>$2</code> 表示正则表达式中的括号匹配项的结果.</p>
<pre class="brush: js">var re = /(\w+)\s(\w+)/;
<pre><code class="language-javascript">var re = /(\w+)\s(\w+)/;
var str = 'John Smith';
str.replace(re, '$2, $1'); // "Smith, John"
RegExp.$1; // "John"
RegExp.$2; // "Smith"
</pre>
</code></pre>
<h2 id="技术指标">技术指标</h2>
<p>非标准. 不属于当前的任何规范.</p>
<h2 id="浏览器适配">浏览器适配</h2>

View File

@@ -5,20 +5,20 @@
</div></div>
<p><strong>rightContext </strong>非标准属性是正则表达式的静态和只读属性,含有最新匹配的右侧子串。 <code>RegExp.$'</code> 是这个属性的别名。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>RegExp</var>.rightContext
<pre><code class="language-javascript"><code><var>RegExp</var>.rightContext
RegExp["$'"]</code>
</pre>
</code></pre>
<h2 id="描述">描述</h2>
<p><code>rightContext</code> 属性是静态的,不是正则表达式独立对象的属性。反之,你应始终将其使用为 <code>RegExp.rightContext</code> 或者 <code>RegExp["$'"]</code></p>
<p><code>rightContext</code> 属性的值是只读的,并且会在匹配成功时修改。</p>
<p>你不能使用属性访问器(<code>RegExp.$'</code>)来使用简写的别名,因为解析器在这里会将其看做字符串的开始,并抛出 <a href="Reference/Global_Objects/SyntaxError" title="SyntaxError 对象代表尝试解析语法上不合法的代码的错误。"><code>SyntaxError</code></a>。使用 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">方括号符号</a>来访问属性。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_rightContext_和_'">使用 <code>rightContext</code><code>$'</code></h3>
<pre class="brush: js">var re = /hello/g;
<pre><code class="language-javascript">var re = /hello/g;
re.test('hello world!');
RegExp.rightContext; // " world!"
RegExp["$'"]; // " world!"
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<p>非标准。并不是任何现行规范的一部分。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>

View File

@@ -3,10 +3,10 @@
<h2 id="Summary" name="Summary">概述</h2>
<p><strong><code>source</code></strong> 属性返回一个值为当前正则表达式对象的模式文本的字符串,该字符串不会包含正则字面量两边的斜杠以及任何的标志字符。</p>
<h2 id="Examples" name="Examples">示例</h2>
<pre class="brush: js">var regex = /fooBar/ig;
<pre><code class="language-javascript">var regex = /fooBar/ig;
console.log(regex.source); // "fooBar",不包含 /.../ 和 "ig"。
</pre>
</code></pre>
<h2 id="Specifications" name="Specifications">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -27,7 +27,7 @@
<p>你不能直接更改这个属性,它是只读的。</p>
<h2 id="例子">例子</h2>
<h3 id="使用带_sticky_标志的正则表达式">使用带 sticky 标志的正则表达式</h3>
<pre class="brush: js">var str = '#foo#';
<pre><code class="language-javascript">var str = '#foo#';
var regex = /foo/y;
regex.lastIndex = 1;
@@ -35,14 +35,14 @@ regex.test(str); // true (译注:此例仅当 lastIndex = 1 时匹配成功
regex.lastIndex = 5;
regex.test(str); // false lastIndex 被 sticky 标志考虑到,从而导致匹配失败)
regex.lastIndex; // 0 (匹配失败后重置)
</pre>
</code></pre>
<h3 id="锚定的_sticky_标志">锚定的 sticky 标志</h3>
<p>火狐的 SpiderMonkey 引擎的几个版本有一个 <a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=773687" rel="noopener">bug</a>,处理 <code>^</code> 断言和 sticky 标志时,会允许使用了 sticky 标志的表达式从 <code>^</code> 断言开始匹配,这是不应该的。这个 bug 是在 Firefox 3.6 之后的某个版本引入的which had the sticky flag but not the bug并于2015年修复。 可能正因为这个 bug ES2015 规范 <a class="external" href="http://www.ecma-international.org/ecma-262/7.0/index.html#sec-assertion" rel="noopener">特别指出</a></p>
<blockquote>
<p>当使用带有y标识的匹配模式时^断言总是会匹配输入的开始位置或者(如果是多行模式)每一行的开始位置。</p>
</blockquote>
<p>正确行为的示例:</p>
<pre class="brush: js">var regex = /^foo/y;
<pre><code class="language-javascript">var regex = /^foo/y;
regex.lastIndex = 2;
regex.test("..foo"); // false - 索引2不是字符串的开始
@@ -51,7 +51,7 @@ regex2.lastIndex = 2;
regex2.test("..foo"); // false - 索引2不是字符串或行的开始
regex2.lastIndex = 2;
regex2.test(".\nfoo"); // true - 索引2是行的开始
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -2,7 +2,7 @@
<div></div>
<p><code><strong>test()</strong></code> 方法执行一个检索,用来查看正则表达式与指定的字符串是否匹配。返回 <code>true</code><code>false</code></p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre><var>regexObj</var>.test(str)</pre>
<pre><var>regexObj</var>.test(str)</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>str</code></dt>
@@ -15,12 +15,12 @@
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_test" name="Example:_Using_test">使用 <code>test()</code></h3>
<p>一个简单的例子,测试 "hello" 是否包含在字符串的最开始,返回布尔值。</p>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">let</span> str <span class="operator token">=</span> <span class="string token">'hello world!'</span><span class="punctuation token">;</span>
<pre><code class="language-javascript"><code class="language-js"><span class="keyword token">let</span> str <span class="operator token">=</span> <span class="string token">'hello world!'</span><span class="punctuation token">;</span>
<span class="keyword token">let</span> result <span class="operator token">=</span> <span class="regex token">/^hello/</span><span class="punctuation token">.</span><span class="function token">test</span><span class="punctuation token">(</span>str<span class="punctuation token">)</span><span class="punctuation token">;</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>result<span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// true</span></code></pre>
<span class="comment token">// true</span></code></code></pre>
<p>下例打印一条信息,该信息内容取决于是否成功通过指定测试:</p>
<pre class="brush: js">function testinput(re, str){
<pre><code class="language-javascript">function testinput(re, str){
var midstring;
if (re.test(str)) {
midstring = " contains ";
@@ -29,7 +29,7 @@ console<span class="punctuation token">.</span><span class="function token">log<
}
console.log(str + midstring + re.source);
}
</pre>
</code></pre>
<h3 id="当设置全局标志的正则使用test()">当设置全局标志的正则使用<code>test()</code></h3>
<p>如果正则表达式设置了全局标志,<code>test() </code>的执行会改变正则表达式   <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex" title="The lastIndex is a read/write integer property of regular expression instances that specifies the index at which to start the next match."><code>lastIndex</code></a>属性。连续的执行<code>test()</code>方法,后续的执行将会从 lastIndex 处开始匹配字符串,(<a href="Reference/Global_Objects/RegExp/exec" title="exec() 方法在一个指定字符串中执行一个搜索匹配。返回一个结果数组或 null。"><code><code>exec()</code></code></a> 同样改变正则本身的 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex" title="The lastIndex is a read/write integer property of regular expression instances that specifies the index at which to start the next match.">lastIndex</a>属性值</code>).</p>
<p>下面的实例表现了这种行为: </p>
@@ -39,7 +39,7 @@ console<span class="punctuation token">.</span><span class="function token">log<
regex.test('foo'); // true
// regex.lastIndex is now at 3
regex.test('foo'); // false</code></pre>
regex.test('foo'); // false</code></code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -6,17 +6,17 @@
<h2 id="Summary" name="Summary">概述</h2>
<p>返回一个字符串,代表当前对象的源代码</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>regexObj</var>.toSource()
</code></pre>
<pre><code class="language-javascript"><code><var>regexObj</var>.toSource()
</code></code></pre>
<h2 id="Description" name="Description">描述</h2>
<p><code>toSource</code>方法返回值如下:</p>
<ul>
<li>对于内置的<code>RegExp</code>对象, <code>toSource</code> 如下字符串:</li>
</ul>
<pre class="brush: js">function RegExp() {
<pre><code class="language-javascript">function RegExp() {
[native code]
}
</pre>
</code></pre>
<ul>
<li>对于一个<code>RegExp实例</code>, <code>toSource返回代表该正则的字符串.</code></li>
</ul>

View File

@@ -4,7 +4,7 @@
<h2 id="Summary" name="Summary">概述</h2>
<p><code><strong>toString()</strong></code> 返回一个表示该正则表达式的字符串。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><var>regexObj</var>.toString()</pre>
<pre><code class="language-javascript"><var>regexObj</var>.toString()</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h2 id="Description" name="Description">描述</h2>
@@ -17,7 +17,7 @@ alert(myExp.toString()); // 显示 "/a+b+c/"
foo = new RegExp("bar", "g");
alert(foo.toString()); // 显示 "/bar/g"
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -27,10 +27,10 @@
<p>你不能直接修改这个属性,它是只读的。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_unicode_属性">使用 <code>unicode</code> 属性</h3>
<pre class="brush: js">var regex = new RegExp('\u{61}', 'u');
<pre><code class="language-javascript">var regex = new RegExp('\u{61}', 'u');
console.log(regex.unicode); // true
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>