aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/reference/global_objects/string
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/javascript/reference/global_objects/string
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/zh-tw/web/javascript/reference/global_objects/string')
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/index.html328
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/match/index.html151
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/padstart/index.html96
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/prototype/index.html176
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/replace/index.html286
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/string/tolowercase/index.html77
6 files changed, 1114 insertions, 0 deletions
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/index.html
new file mode 100644
index 0000000000..ad4474693a
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/index.html
@@ -0,0 +1,328 @@
+---
+title: 字串
+slug: Web/JavaScript/Reference/Global_Objects/String
+tags:
+ - ECMAScript 2015
+ - JavaScript
+ - Reference
+ - String
+translation_of: Web/JavaScript/Reference/Global_Objects/String
+---
+<p>{{JSRef("Global_Objects", "String")}}</p>
+
+<p><strong><code>String</code></strong> 全域物件為字串的構造函數,或是一個字符序列。</p>
+
+<h2 id="Syntax" name="Syntax">語法</h2>
+
+<p>字串文字採用下列形式:</p>
+
+<pre>'string text' "string text" "中文 español deutsch English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ் עברית"</pre>
+
+<p>字串也可以被全域的 <code>String</code> 物件建立:</p>
+
+<pre>String(thing)</pre>
+
+<h3 id="Parameters" name="Parameters">參數</h3>
+
+<dl>
+ <dt><code>thing</code></dt>
+ <dd>任何要轉換成字串的物件。</dd>
+</dl>
+
+<h3 id="樣板字面值">樣板字面值</h3>
+
+<p>自 ECMAScript 2015,字串文字也可以是<a href="https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Template_literals">樣板字面值(Template literals)</a>:</p>
+
+<pre>`hello world` `hello! world!` `hello ${who}` escape `&lt;a&gt;${who}&lt;/a&gt;`</pre>
+
+<h3 id="跳脫符號">跳脫符號</h3>
+
+<p>除了常規的、可印出來的字元,特殊字元也可以被跳脫符號來表示編碼。</p>
+
+<table>
+ <thead>
+ <tr>
+ <th scope="col">代碼</th>
+ <th scope="col">輸出</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>\0</code></td>
+ <td>空字元</td>
+ </tr>
+ <tr>
+ <td><code>\'</code></td>
+ <td>單引號</td>
+ </tr>
+ <tr>
+ <td><code>\"</code></td>
+ <td>雙引號</td>
+ </tr>
+ <tr>
+ <td><code>\\</code></td>
+ <td>反斜線</td>
+ </tr>
+ <tr>
+ <td><code>\n</code></td>
+ <td>斷行</td>
+ </tr>
+ <tr>
+ <td><code>\r</code></td>
+ <td>回車</td>
+ </tr>
+ <tr>
+ <td><code>\v</code></td>
+ <td>垂直制表</td>
+ </tr>
+ <tr>
+ <td><code>\t</code></td>
+ <td>制表</td>
+ </tr>
+ <tr>
+ <td><code>\b</code></td>
+ <td>退格</td>
+ </tr>
+ <tr>
+ <td><code>\f</code></td>
+ <td>饋頁</td>
+ </tr>
+ <tr>
+ <td><code>\uXXXX</code></td>
+ <td>unicode 代碼</td>
+ </tr>
+ <tr>
+ <td><code>\u{X}</code> ... <code>\u{XXXXXX}</code></td>
+ <td>unicode 代碼 {{experimental_inline}}</td>
+ </tr>
+ <tr>
+ <td><code>\xXX</code></td>
+ <td>Latin-1 字元</td>
+ </tr>
+ </tbody>
+</table>
+
+<dl>
+</dl>
+
+<div class="note">
+<p>和其他語言不同,JavaScript 將單引號字串和雙引號字串是做相同;因此,上述的序列可以在單引號或雙引號中作用。</p>
+</div>
+
+<dl>
+</dl>
+
+<h3 id="長字面值字串">長字面值字串</h3>
+
+<p>有些時候,你的程式碼會包含非常長的字串。 為了不讓長字串無止盡地往下長,抑或是在你心血來潮的時候,你可能希望將這樣長的字串能夠斷成多行卻不影響到實際的內容。</p>
+
+<p>你可以用 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition_()">+</a> 運算子附加多個字串在一起,像是這樣:</p>
+
+<pre><code>let longString = "This is a very long string which needs " +
+ "to wrap across multiple lines because " +
+ "otherwise my code is unreadable.";</code></pre>
+
+<p>或者,你可以在每一行尾端用反斜線字元("\")表示字串會繼續被顯示在下一列。 你必須要確定在反斜線後面沒有任何空白或其他字元,甚至是縮排;否則這個方法將失效。 這個形式看起來像這樣:</p>
+
+<pre><code>let longString = "This is a very long string which needs \
+to wrap across multiple lines because \
+otherwise my code is unreadable.";</code></pre>
+
+<p>這兩個方法都會建立相同的字串內容。</p>
+
+<h2 id="Description" name="Description">說明</h2>
+
+<p>字串對於能保留以文字形式表達的資料這件事來說,是有用的。在字串上,一些最常被使用的運算即確認字串長度 {{jsxref("String.length", "length")}} ,用 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/String_Operators">+ 或 += 字串運算元</a> 建造或者串接字串,用 {{jsxref("String.indexOf", "indexOf")}} 方法檢查?子字串是否存在或子字串的位置,或者是用 {{jsxref("String.substring", "substring")}} 方法將子字串抽取出來。</p>
+
+<h3 id="Character_access" name="Character_access">存取字元</h3>
+
+<p>有兩個方法可以存取字串中個別的字元。第一個是用 {{jsxref("String.charAt", "charAt")}} 方法:</p>
+
+<pre class="brush: js">return 'cat'.charAt(1); // 回傳 "a"
+</pre>
+
+<p>另一個(在ECMAScript 5中被提到)方法是將字串當作一個類似陣列的物件,直接存取字串中對應的數值索引。</p>
+
+<pre class="brush: js">return 'cat'[1]; // 回傳 "a"
+</pre>
+
+<p>對於存取字元使用的括號表達式,沒辦法去刪除或指派一個值給這些屬性。 這些屬性既非可寫的,也非可設定的。(參見 {{jsxref("Object.defineProperty")}})</p>
+
+<h3 id="Comparing_strings" name="Comparing_strings">比較字串</h3>
+
+<p>C 語言的開發者有 <code>strcmp()</code> 函式可以用來比較字串。 在 JavaScript 中,你只能用<a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">小於和大於運算子</a>:</p>
+
+<pre class="brush: js">var a = "a";
+var b = "b";
+if (a &lt; b) // true
+ print(a + " 小於 " + b);
+else if (a &gt; b)
+ print(a + " 大於 " + b);
+else
+ print(a + " 和 " + b + " 相等");
+</pre>
+
+<p>這樣類似的結果,也能使用繼承 <code>String</code> 實體的 {{jsxref("String.localeCompare", "localeCompare")}} 方法來實現。</p>
+
+<h3 id="分辨_string_原始型別和_String_物件">分辨 string 原始型別和 <code>String</code> 物件</h3>
+
+<p>請注意,JavaScript 會區別 <code>String</code> 物件和原始字串({{jsxref("Global_Objects/Boolean", "Boolean")}} 和 {{jsxref("Global_Objects/Number", "Numbers")}} 也是如此)。</p>
+
+<p>String literals (denoted by double or single quotes) and strings returned from <code>String</code> calls in a non-constructor context (i.e., without using the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new"><code>new</code> keyword</a>) are primitive strings. JavaScript automatically converts primitives to <code>String</code> objects, so that it's possible to use <code>String</code> object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.</p>
+
+<pre class="brush: js">var s_prim = "foo";
+var s_obj = new String(s_prim);
+
+console.log(typeof s_prim); // 印出 "string"
+console.log(typeof s_obj); // 印出 "object"
+</pre>
+
+<p>字串原始型別和 <code>String</code> 物件也會在使用 {{jsxref("Global_Objects/eval", "eval")}} 時給出不同的結果。 原始型別傳進 <code>eval</code> 會被視為原始代碼;<code>String</code> 物件則會回傳,且被視作是其他物件。舉個例子:</p>
+
+<pre class="brush: js">s1 = "2 + 2"; // 建立一個字串原始型別
+s2 = new String("2 + 2"); // 建立一個字串物件
+console.log(eval(s1)); // 回傳數字 4
+console.log(eval(s2)); // 回傳字串 "2 + 2"
+</pre>
+
+<p>因為一些原因,程式碼也許在遇到 <code>String</code> 物件時,但需要的卻是字串原始型別;儘管如此,通常作者們不需要擔心它的差異。</p>
+
+<p>一個 <code>String</code> 物件總能夠使用 {{jsxref("String.valueOf", "valueOf")}} 方法被轉換成自身的原始副本。</p>
+
+<pre class="brush: js">console.log(eval(s2.valueOf())); // 回傳數字 4
+</pre>
+
+<div class="note"><strong>注意:</strong> 對於在 JavaScript 中其他可用的字串方法,請參閱這篇文章<a href="/en-US/docs/Web/JavaScript/Typed_arrays/StringView" title="/en-US/docs/Web/JavaScript/Typed_arrays/StringView"><code>StringView</code> – a C-like representation of strings based on typed arrays</a>。</div>
+
+<h2 id="Properties" name="Properties">屬性</h2>
+
+<dl>
+ <dt>{{jsxref("String.prototype")}}</dt>
+ <dd>能讓字串物件增加屬性。</dd>
+</dl>
+
+<div>{{jsOverrides("Function", "Properties", "prototype")}}</div>
+
+<h2 id="Methods" name="Methods">方法</h2>
+
+<dl>
+ <dt>{{jsxref("String.fromCharCode()")}}</dt>
+ <dd>利用 Unicode 值的序列建立並回傳一個字串。</dd>
+ <dt>{{jsxref("String.fromCodePoint()")}} {{experimental_inline}}</dt>
+ <dd>利用編碼位置的序列建立並回傳一個字串。</dd>
+</dl>
+
+<div>{{jsOverrides("Function", "Methods", "fromCharCode", "fromCodePoint")}}</div>
+
+<h2 id="String_通用方法"><code>String</code> 通用方法</h2>
+
+<div class="warning">
+<p>字串通用方法是非標準化的、被棄用的,也有近期將被刪除的。</p>
+</div>
+
+<p>The <code>String </code>instance methods are also available in Firefox as of JavaScript 1.6 (though not part of the ECMAScript standard) on the String object for applying String methods to any object:</p>
+
+<pre class="brush: js">var num = 15;
+alert(String.replace(num, /5/, '2'));
+</pre>
+
+<p class="brush: js"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Array_generic_methods">Generics</a> are also available on {{jsxref("Global_Objects/Array", "Array")}} methods.</p>
+
+<p class="brush: js">The following is a shim to provide support to non-supporting browsers:</p>
+
+<pre class="brush: js">/*globals define*/
+// Assumes all supplied String instance methods already present
+// (one may use shims for these if not available)
+(function () {
+ 'use strict';
+
+ var i,
+ // We could also build the array of methods with the following, but the
+ // getOwnPropertyNames() method is non-shimable:
+ // Object.getOwnPropertyNames(String).filter(function (methodName)
+ // {return typeof String[methodName] === 'function'});
+ methods = [
+ 'quote', 'substring', 'toLowerCase', 'toUpperCase', 'charAt',
+ 'charCodeAt', 'indexOf', 'lastIndexOf', 'startsWith', 'endsWith',
+ 'trim', 'trimLeft', 'trimRight', 'toLocaleLowerCase',
+ 'toLocaleUpperCase', 'localeCompare', 'match', 'search',
+ 'replace', 'split', 'substr', 'concat', 'slice'
+ ],
+ methodCount = methods.length,
+ assignStringGeneric = function (methodName) {
+ var method = String.prototype[methodName];
+ String[methodName] = function (arg1) {
+ return method.apply(arg1, Array.prototype.slice.call(arguments, 1));
+ };
+ };
+
+ for (i = 0; i &lt; methodCount; i++) {
+ assignStringGeneric(methods[i]);
+ }
+}());</pre>
+
+<h2 id="String_instances" name="String_instances"><code>String</code> instances</h2>
+
+<h3 id="Properties_2">Properties</h3>
+
+<p>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}</p>
+
+<p>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods')}}</p>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="String_conversion">String conversion</h3>
+
+<p>It's possible to use <code>String</code> as a "safer" {{jsxref("String.toString", "toString")}} alternative, as although it still normally calls the underlying <code>toString</code>, it also works for <code>null</code> and <code>undefined</code>. For example:</p>
+
+<pre class="brush: js">var outputStrings = [];
+for (let i = 0, n = inputValues.length; i &lt; n; ++i) {
+ outputStrings.push(String(inputValues[i]));
+}
+</pre>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5', 'String')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-string-objects', 'String')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string-objects', 'String')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.String.String")}}</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{domxref("DOMString")}}</li>
+ <li><a href="/en-US/Add-ons/Code_snippets/StringView"><code>StringView</code> — a C-like representation of strings based on typed arrays</a></li>
+ <li><a href="/en-US/docs/Web/API/DOMString/Binary">Binary strings</a></li>
+</ul>
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/match/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/match/index.html
new file mode 100644
index 0000000000..664b28462f
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/match/index.html
@@ -0,0 +1,151 @@
+---
+title: String.prototype.match()
+slug: Web/JavaScript/Reference/Global_Objects/String/match
+translation_of: Web/JavaScript/Reference/Global_Objects/String/match
+---
+<div>{{JSRef}}</div>
+
+<p>The <strong><code>match()</code></strong> method retrieves the matches when matching a <em>string</em> against a <em>regular expression</em>.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><var>str</var>.match(<var>regexp</var>)</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>regexp</code></dt>
+ <dd>一個正規表達式的物件。 若傳入一個非正規表達式的物件<code>obj</code>,則會視為傳入 <code>new RegExp(obj)</code>。若只呼叫<code>match()</code>而沒有傳入任何參數,則會回傳內含一個空字串的陣列,即<code>[""]</code>。</dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>If the string matches the expression, it will return an {{jsxref("Array")}} containing the entire matched string as the first element, followed by any results captured in parentheses. If there were no matches, {{jsxref("null")}} is returned.</p>
+
+<h2 id="Description">Description</h2>
+
+<p>If the regular expression does not include the <code>g</code> flag, <code>str.match()</code> will return the same result as {{jsxref("RegExp.prototype.exec()", "RegExp.exec()")}}. The returned {{jsxref("Array")}} has an extra <code>input</code> property, which contains the original string that was parsed. In addition, it has an <code>index</code> property, which represents the zero-based index of the match in the string.</p>
+
+<p>If the regular expression includes the <code>g</code> flag, the method returns an {{jsxref("Array")}} containing all matched substrings rather than match objects. Captured groups are not returned. If there were no matches, the method returns {{jsxref("null")}}.</p>
+
+<h3 id="See_also_RegExp_methods">See also: <code>RegExp</code> methods</h3>
+
+<ul>
+ <li>If you need to know if a string matches a regular expression {{jsxref("RegExp")}}, use {{jsxref("RegExp.prototype.test()", "RegExp.test()")}}.</li>
+ <li>If you only want the first match found, you might want to use {{jsxref("RegExp.prototype.exec()", "RegExp.exec()")}} instead.</li>
+ <li>if you want to obtain capture groups and the global flag is set, you need to use {{jsxref("RegExp.prototype.exec()", "RegExp.exec()")}} instead.</li>
+</ul>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Using_match()">Using <code>match()</code></h3>
+
+<p>In the following example, <code>match()</code> is used to find <code>'Chapter'</code> followed by 1 or more numeric characters followed by a decimal point and numeric character 0 or more times. The regular expression includes the <code>i</code> flag so that upper/lower case differences will be ignored.</p>
+
+<pre class="brush: js">var str = 'For more information, see Chapter 3.4.5.1';
+var re = /see (chapter \d+(\.\d)*)/i;
+var found = str.match(re);
+
+console.log(found);
+
+// logs [ 'see Chapter 3.4.5.1',
+// 'Chapter 3.4.5.1',
+// '.1',
+// index: 22,
+// input: 'For more information, see Chapter 3.4.5.1' ]
+
+// 'see Chapter 3.4.5.1' is the whole match.
+// 'Chapter 3.4.5.1' was captured by '(chapter \d+(\.\d)*)'.
+// '.1' was the last value captured by '(\.\d)'.
+// The 'index' property (22) is the zero-based index of the whole match.
+// The 'input' property is the original string that was parsed.</pre>
+
+<h3 id="Using_global_and_ignore_case_flags_with_match()">Using global and ignore case flags with <code>match()</code></h3>
+
+<p>The following example demonstrates the use of the global and ignore case flags with <code>match()</code>. All letters A through E and a through e are returned, each its own element in the array.</p>
+
+<pre class="brush: js">var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+var regexp = /[A-E]/gi;
+var matches_array = str.match(regexp);
+
+console.log(matches_array);
+// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']
+</pre>
+
+<h3 id="Using_match()_with_no_parameter">Using <code>match()</code> with no parameter</h3>
+
+<pre class="brush: js">var str = "Nothing will come of nothing.";
+
+str.match(); // returns [""]</pre>
+
+<h3 id="A_non-RegExp_object_as_the_parameter">A non-RegExp object as the parameter</h3>
+
+<p>When the parameter is a string or a number, it is implicitly converted to a {{jsxref("RegExp")}} by using new RegExp(obj). If it is a positive number with a positive sign,the RegExp() method will ignore the positive sign. </p>
+
+<pre class="brush: js">var str1 = "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.",
+ str2 = "My grandfather is 65 years old and My grandmother is 63 years old.",
+ str3 = "The contract was declared null and void.";
+str1.match("number");   // "number" is a string. returns ["number"]
+str1.match(NaN);   // the type of NaN is the number. returns ["NaN"]
+str1.match(Infinity);   // the type of Infinity is the number. returns ["Infinity"]
+str1.match(+Infinity);  // returns ["Infinity"]
+str1.match(-Infinity);  // returns ["-Infinity"]
+str2.match(65);   // returns ["65"]
+str2.match(+65);   // A number with a positive sign. returns ["65"]
+str3.match(null);   // returns ["null"]</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.2.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.4.10', 'String.prototype.match')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.match', 'String.prototype.match')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.match', 'String.prototype.match')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.String.match")}}</p>
+
+<h2 id="Firefox-specific_notes">Firefox-specific notes</h2>
+
+<ul>
+ <li><code>flags</code> was a non standard second argument only available in Gecko : <var>str</var>.match(<var>regexp, flags</var>)</li>
+ <li>Starting with Gecko 27 {{geckoRelease(27)}}, this method has been adjusted to conform with the ECMAScript specification. When <code>match()</code> is called with a global regular expression, the {{jsxref("RegExp.lastIndex")}} property (if specified) will be reset to <code>0</code> ({{bug(501739)}}).</li>
+ <li>Starting with Gecko 39 {{geckoRelease(39)}}, the non-standard <code>flags</code> argument is deprecated and throws a console warning ({{bug(1142351)}}).</li>
+ <li>Starting with Gecko 47 {{geckoRelease(47)}}, the non-standard <code>flags</code> argument is no longer supported in non-release builds and will soon be removed entirely ({{bug(1245801)}}).</li>
+ <li>Starting with Gecko 49 {{geckoRelease(49)}}, the non-standard <code>flags</code> argument is no longer supported ({{bug(1108382)}}).</li>
+</ul>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("RegExp")}}</li>
+ <li>{{jsxref("RegExp.prototype.exec()")}}</li>
+ <li>{{jsxref("RegExp.prototype.test()")}}</li>
+</ul>
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/padstart/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/padstart/index.html
new file mode 100644
index 0000000000..8a08d5924f
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/padstart/index.html
@@ -0,0 +1,96 @@
+---
+title: String.prototype.padStart()
+slug: Web/JavaScript/Reference/Global_Objects/String/padStart
+translation_of: Web/JavaScript/Reference/Global_Objects/String/padStart
+---
+<div>{{JSRef}}{{SeeCompatTable}}</div>
+
+<p><strong><code>padStart()</code></strong><code> 會將用給定用於填充的字串,以重複的方式,插入到目標字串的起頭(左側),直到目標字串到達指定長度。</code></p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><var>str</var>.padStart(<var>targetLength</var> [, <var>padString</var>])</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>targetLength</code></dt>
+ <dd>目標字串被填充後的長度。如果此參數小於原字串的長度,那將直接返回原字串。</dd>
+ <dt><code>padString</code> {{optional_inline}}</dt>
+ <dd>用來填充的字串。如果填充字串太長,則由左側開始,擷取所需要的長度。此參數預設值是空白 " " (U+0020).</dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>目標字串被填充到指定長度後,所得的新字串。</p>
+
+<h2 id="Examples">Examples</h2>
+
+<pre class="brush: js">'abc'.padStart(10); // "       abc"
+'abc'.padStart(10, "foo"); // "foofoofabc"
+'abc'.padStart(6,"123465"); // "123abc"
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<p>這個方法還沒有被納入 ECMAScript 標準。現在還只是個<a href="https://github.com/tc39/proposal-string-pad-start-end">提案</a>。</p>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(57)}} </td>
+ <td>15</td>
+ <td>{{CompatGeckoDesktop(51)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOpera(44)}}</td>
+ <td>{{CompatSafari(10)}}</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>{{CompatUnknown}}</td>
+ <td>{{CompatChrome(57)}}</td>
+ <td>{{CompatGeckoMobile(51)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatSafari(10)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("String.padEnd()")}}</li>
+</ul>
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/prototype/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/prototype/index.html
new file mode 100644
index 0000000000..41c7333dc6
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/prototype/index.html
@@ -0,0 +1,176 @@
+---
+title: String.prototype
+slug: Web/JavaScript/Reference/Global_Objects/String/prototype
+translation_of: Web/JavaScript/Reference/Global_Objects/String
+---
+<div>{{JSRef}}</div>
+
+<p>The <strong><code>String.prototype</code></strong> property represents the {{jsxref("String")}} prototype object.</p>
+
+<div>{{js_property_attributes(0, 0, 0)}}</div>
+
+<h2 id="Description">Description</h2>
+
+<p>All {{jsxref("String")}} instances inherit from <code>String.prototype</code>. Changes to the <code>String</code> prototype object are propagated to all {{jsxref("String")}} instances.</p>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt><code>String.prototype.constructor</code></dt>
+ <dd>Specifies the function that creates an object's prototype.</dd>
+ <dt>{{jsxref("String.prototype.length")}}</dt>
+ <dd>Reflects the length of the string.</dd>
+ <dt><code><em>N</em></code></dt>
+ <dd>Used to access the character in the <em>N</em>th position where <em>N</em> is a positive integer between 0 and one less than the value of {{jsxref("String.length", "length")}}. These properties are read-only.</dd>
+</dl>
+
+<h2 id="Methods">Methods</h2>
+
+<h3 id="Methods_unrelated_to_HTML">Methods unrelated to HTML</h3>
+
+<dl>
+ <dt>{{jsxref("String.prototype.charAt()")}}</dt>
+ <dd>Returns the character (exactly one UTF-16 code unit) at the specified index.</dd>
+ <dt>{{jsxref("String.prototype.charCodeAt()")}}</dt>
+ <dd>Returns a number that is the UTF-16 code unit value at the given index.</dd>
+ <dt>{{jsxref("String.prototype.codePointAt()")}}</dt>
+ <dd>Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified index.</dd>
+ <dt>{{jsxref("String.prototype.concat()")}}</dt>
+ <dd>Combines the text of two strings and returns a new string.</dd>
+ <dt>{{jsxref("String.prototype.includes()")}}</dt>
+ <dd>Determines whether one string may be found within another string.</dd>
+ <dt>{{jsxref("String.prototype.endsWith()")}}</dt>
+ <dd>Determines whether a string ends with the characters of another string.</dd>
+ <dt>{{jsxref("String.prototype.indexOf()")}}</dt>
+ <dd>Returns the index within the calling {{jsxref("String")}} object of the first occurrence of the specified value, or -1 if not found.</dd>
+ <dt>{{jsxref("String.prototype.lastIndexOf()")}}</dt>
+ <dd>Returns the index within the calling {{jsxref("String")}} object of the last occurrence of the specified value, or -1 if not found.</dd>
+ <dt>{{jsxref("String.prototype.localeCompare()")}}</dt>
+ <dd>Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.</dd>
+ <dt>{{jsxref("String.prototype.match()")}}</dt>
+ <dd>Used to match a regular expression against a string.</dd>
+ <dt>{{jsxref("String.prototype.normalize()")}}</dt>
+ <dd>Returns the Unicode Normalization Form of the calling string value.</dd>
+ <dt>{{jsxref("String.prototype.padEnd()")}}</dt>
+ <dd>Pads the current string from the end with a given string to create a new string from a given length.</dd>
+ <dt>{{jsxref("String.prototype.padStart()")}}</dt>
+ <dd>Pads the current string from the start with a given string to create a new string from a given length.</dd>
+ <dt><s class="obsoleteElement">{{jsxref("String.prototype.quote()")}} {{obsolete_inline}}</s></dt>
+ <dd><s class="obsoleteElement">Wraps the string in double quotes ("<code>"</code>").</s></dd>
+ <dt>{{jsxref("String.prototype.repeat()")}}</dt>
+ <dd>Returns a string consisting of the elements of the object repeated the given times.</dd>
+ <dt>{{jsxref("String.prototype.replace()")}}</dt>
+ <dd>Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.</dd>
+ <dt>{{jsxref("String.prototype.search()")}}</dt>
+ <dd>Executes the search for a match between a regular expression and a specified string.</dd>
+ <dt>{{jsxref("String.prototype.slice()")}}</dt>
+ <dd>Extracts a section of a string and returns a new string.</dd>
+ <dt>{{jsxref("String.prototype.split()")}}</dt>
+ <dd>Splits a {{jsxref("Global_Objects/String", "String")}} object into an array of strings by separating the string into substrings.</dd>
+ <dt>{{jsxref("String.prototype.startsWith()")}}</dt>
+ <dd>Determines whether a string begins with the characters of another string.</dd>
+ <dt>{{jsxref("String.prototype.substr()")}}</dt>
+ <dd>Returns the characters in a string beginning at the specified location through the specified number of characters.</dd>
+ <dt>{{jsxref("String.prototype.substring()")}}</dt>
+ <dd>Returns the characters in a string between two indexes into the string.</dd>
+ <dt>{{jsxref("String.prototype.toLocaleLowerCase()")}}</dt>
+ <dd>The characters within a string are converted to lower case while respecting the current locale. For most languages, this will return the same as {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}.</dd>
+ <dt>{{jsxref("String.prototype.toLocaleUpperCase()")}}</dt>
+ <dd>The characters within a string are converted to upper case while respecting the current locale. For most languages, this will return the same as {{jsxref("String.prototype.toUpperCase()", "toUpperCase()")}}.</dd>
+ <dt>{{jsxref("String.prototype.toLowerCase()")}}</dt>
+ <dd>Returns the calling string value converted to lower case.</dd>
+ <dt>{{jsxref("String.prototype.toSource()")}} {{non-standard_inline}}</dt>
+ <dd>Returns an object literal representing the specified object; you can use this value to create a new object. Overrides the {{jsxref("Object.prototype.toSource()")}} method.</dd>
+ <dt>{{jsxref("String.prototype.toString()")}}</dt>
+ <dd>Returns a string representing the specified object. Overrides the {{jsxref("Object.prototype.toString()")}} method.</dd>
+ <dt>{{jsxref("String.prototype.toUpperCase()")}}</dt>
+ <dd>Returns the calling string value converted to uppercase.</dd>
+ <dt>{{jsxref("String.prototype.trim()")}}</dt>
+ <dd>Trims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.</dd>
+ <dt>{{jsxref("String.prototype.trimLeft()")}} {{non-standard_inline}}</dt>
+ <dd>Trims whitespace from the left side of the string.</dd>
+ <dt>{{jsxref("String.prototype.trimRight()")}} {{non-standard_inline}}</dt>
+ <dd>Trims whitespace from the right side of the string.</dd>
+ <dt>{{jsxref("String.prototype.valueOf()")}}</dt>
+ <dd>Returns the primitive value of the specified object. Overrides the {{jsxref("Object.prototype.valueOf()")}} method.</dd>
+ <dt>{{jsxref("String.prototype.@@iterator()", "String.prototype[@@iterator]()")}}</dt>
+ <dd>Returns a new <code>Iterator</code> object that iterates over the code points of a String value, returning each code point as a String value.</dd>
+</dl>
+
+<h3 id="HTML_wrapper_methods">HTML wrapper methods</h3>
+
+<p>These methods are of limited use, as they provide only a subset of the available HTML tags and attributes.</p>
+
+<dl>
+ <dt>{{jsxref("String.prototype.anchor()")}}</dt>
+ <dd>{{htmlattrxref("name", "a", "&lt;a name=\"name\"&gt;")}} (hypertext target)</dd>
+ <dt>{{jsxref("String.prototype.big()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("big")}}</dd>
+ <dt>{{jsxref("String.prototype.blink()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("blink")}}</dd>
+ <dt>{{jsxref("String.prototype.bold()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("b")}}</dd>
+ <dt>{{jsxref("String.prototype.fixed()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("tt")}}</dd>
+ <dt>{{jsxref("String.prototype.fontcolor()")}} {{deprecated_inline}}</dt>
+ <dd>{{htmlattrxref("color", "font", "&lt;font color=\"color\"&gt;")}}</dd>
+ <dt>{{jsxref("String.prototype.fontsize()")}} {{deprecated_inline}}</dt>
+ <dd>{{htmlattrxref("size", "font", "&lt;font size=\"size\"&gt;")}}</dd>
+ <dt>{{jsxref("String.prototype.italics()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("i")}}</dd>
+ <dt>{{jsxref("String.prototype.link()")}}</dt>
+ <dd>{{htmlattrxref("href", "a", "&lt;a href=\"url\"&gt;")}} (link to URL)</dd>
+ <dt>{{jsxref("String.prototype.small()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("small")}}</dd>
+ <dt>{{jsxref("String.prototype.strike()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("strike")}}</dd>
+ <dt>{{jsxref("String.prototype.sub()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("sub")}}</dd>
+ <dt>{{jsxref("String.prototype.sup()")}} {{deprecated_inline}}</dt>
+ <dd>{{HTMLElement("sup")}}</dd>
+</dl>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.3.1', 'String.prototype')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype', 'String.prototype')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype', 'String.prototype')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.String.prototype")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("String")}}</li>
+ <li>{{jsxref("Function.prototype")}}</li>
+</ul>
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/replace/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/replace/index.html
new file mode 100644
index 0000000000..1c42d9925f
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/replace/index.html
@@ -0,0 +1,286 @@
+---
+title: String.prototype.replace()
+slug: Web/JavaScript/Reference/Global_Objects/String/replace
+translation_of: Web/JavaScript/Reference/Global_Objects/String/replace
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>replace()</code></strong> 方法會傳回一個新字串,此新字串是透過將原字串與 <code>pattern</code> 比對,以 <code>replacement</code> 取代吻合處而生成。<code>pattern</code> 可以是字串或 {{jsxref("RegExp")}},而 <code>replacement</code> 可以是字串或函式(會在每一次匹配時被呼叫)。</p>
+
+<div class="note">
+<p>備註:原始的字串會保持不變。</p>
+</div>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox"><var>str</var>.replace(<var>regexp</var>|<var>substr</var>, <var>newSubstr</var>|<var>function</var>)</pre>
+
+<h3 id="參數">參數</h3>
+
+<dl>
+ <dt><code>regexp</code> (pattern)</dt>
+ <dd>{{jsxref("RegExp")}} 的物件或文字。 被比對出來的部分將會被取代為 <code>newSubStr</code> 或是取代為 <code>function</code> 的回傳值。</dd>
+ <dt><code>substr</code> (pattern)</dt>
+ <dd>要被 <code>newSubStr</code> 取代的 {{jsxref("String")}}。它被視為逐字字符串,並且不會被解釋為正則表達式。只會替換第一次出現。</dd>
+ <dt><code>newSubStr</code> (replacement)</dt>
+ <dd>The {{jsxref("String")}} that replaces the substring specified by the specified <code>regexp</code> or <code>substr</code> parameter. A number of special replacement patterns are supported; see the "<a href="#指定一個字串為參數">Specifying a string as a parameter</a>" section below.</dd>
+ <dt><code>function</code> (replacement)</dt>
+ <dd>A function to be invoked to create the new substring to be used to replace the matches to the given <code>regexp</code> or <code>substr</code>. The arguments supplied to this function are described in the "<a href="#指定一個函式為參數">Specifying a function as a parameter</a>" section below.</dd>
+</dl>
+
+<h3 id="回傳值">回傳值</h3>
+
+<p>A new string with some or all matches of a pattern replaced by a replacement.</p>
+
+<h2 id="描述">描述</h2>
+
+<p>這個方法不會變更所呼叫的 {{jsxref("String")}}。它只會回傳新的字串。</p>
+
+<p>To perform a global search and replace, include the <code>g</code> switch in the regular expression.</p>
+
+<h3 id="指定一個字串為參數">指定一個字串為參數</h3>
+
+<p>The replacement string can include the following special replacement patterns:</p>
+
+<table class="fullwidth-table">
+ <tbody>
+ <tr>
+ <td class="header">Pattern</td>
+ <td class="header">Inserts</td>
+ </tr>
+ <tr>
+ <td><code>$$</code></td>
+ <td>Inserts a "$".</td>
+ </tr>
+ <tr>
+ <td><code>$&amp;</code></td>
+ <td>Inserts the matched substring.</td>
+ </tr>
+ <tr>
+ <td><code>$`</code></td>
+ <td>Inserts the portion of the string that precedes the matched substring.</td>
+ </tr>
+ <tr>
+ <td><code>$'</code></td>
+ <td>Inserts the portion of the string that follows the matched substring.</td>
+ </tr>
+ <tr>
+ <td><code>$<em>n</em></code></td>
+ <td>Where <code><em>n</em></code> is a positive integer less than 100, inserts the <em>n</em>th parenthesized submatch string, provided the first argument was a {{jsxref("RegExp")}} object.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h3 id="指定一個函式為參數">指定一個函式為參數</h3>
+
+<p>You can specify a function as the second parameter. In this case, the function will be invoked after the match has been performed. The function's result (return value) will be used as the replacement string. (Note: the above-mentioned special replacement patterns do <em>not</em> apply in this case.) Note that the function will be invoked multiple times for each full match to be replaced if the regular expression in the first parameter is global.</p>
+
+<p>The arguments to the function are as follows:</p>
+
+<table class="fullwidth-table">
+ <tbody>
+ <tr>
+ <td class="header">Possible name</td>
+ <td class="header">Supplied value</td>
+ </tr>
+ <tr>
+ <td><code>match</code></td>
+ <td>The matched substring. (Corresponds to <code>$&amp;</code> above.)</td>
+ </tr>
+ <tr>
+ <td><code>p1, p2, ...</code></td>
+ <td>The <em>n</em>th parenthesized submatch string, provided the first argument to <code>replace()</code> was a {{jsxref("RegExp")}} object. (Corresponds to <code>$1</code>, <code>$2</code>, etc. above.) For example, if <code>/(\a+)(\b+)/</code>, was given, <code>p1</code> is the match for <code>\a+</code>, and <code>p2</code> for <code>\b+</code>.</td>
+ </tr>
+ <tr>
+ <td><code>offset</code></td>
+ <td>The offset of the matched substring within the whole string being examined. (For example, if the whole string was <code>'abcd'</code>, and the matched substring was <code>'bc'</code>, then this argument will be 1.)</td>
+ </tr>
+ <tr>
+ <td><code>string</code></td>
+ <td>The whole string being examined.</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>(The exact number of arguments will depend on whether the first argument was a {{jsxref("RegExp")}} object and, if so, how many parenthesized submatches it specifies.)</p>
+
+<p>The following example will set <code>newString</code> to <code>'abc - 12345 - #$*%'</code>:</p>
+
+<pre class="brush: js">function replacer(match, p1, p2, p3, offset, string) {
+ // p1 is nondigits, p2 digits, and p3 non-alphanumerics
+ return [p1, p2, p3].join(' - ');
+}
+var newString = 'abc12345#$*%'.replace(/([^\d]*)(\d*)([^\w]*)/, replacer);
+console.log(newString); // abc - 12345 - #$*%
+</pre>
+
+<h2 id="範例">範例</h2>
+
+<h3 id="於_replace()_中定義正則表示式">於 <code>replace()</code> 中定義正則表示式</h3>
+
+<p>下例的正規表達式被定義為 <code>replace()</code>、並包含了忽略大小寫的 flag。</p>
+
+<pre class="brush: js">var str = 'Twas the night before Xmas...';
+var newstr = str.replace(/xmas/i, 'Christmas');
+console.log(newstr); // Twas the night before Christmas...
+</pre>
+
+<p>上例會顯示「Twas the night before Christmas...」</p>
+
+<h3 id="使用_global_及_ignore_來配合_replace()">使用 <code>global</code> 及 <code>ignore</code> 來配合 <code>replace()</code></h3>
+
+<p>Global replace can only be done with a regular expression. In the following example, the regular expression includes the global and ignore case flags which permits <code>replace()</code> to replace each occurrence of 'apples' in the string with 'oranges'.</p>
+
+<pre class="brush: js">var re = /apples/gi;
+var str = 'Apples are round, and apples are juicy.';
+var newstr = str.replace(re, 'oranges');
+console.log(newstr); // oranges are round, and oranges are juicy.
+</pre>
+
+<p>上例會顯示「oranges are round, and oranges are juicy」。</p>
+
+<h3 id="替換字串中的單字">替換字串中的單字</h3>
+
+<p>下例程式將切換字串內的單字。對 replacement text 而言,程式會使用 <code>$1</code> and <code>$2</code> 的 replacement pattern。</p>
+
+<pre class="brush: js">var re = /(\w+)\s(\w+)/;
+var str = 'John Smith';
+var newstr = str.replace(re, '$2, $1');
+console.log(newstr); // Smith, John
+</pre>
+
+<p>上例會顯示「Smith, John」。</p>
+
+<h3 id="使用行內函式來修改匹配的字元">使用行內函式來修改匹配的字元</h3>
+
+<p>In this example, all occurrences of capital letters in the string are converted to lower case, and a hyphen is inserted just before the match location. The important thing here is that additional operations are needed on the matched item before it is given back as a replacement.</p>
+
+<p>The replacement function accepts the matched snippet as its parameter, and uses it to transform the case and concatenate the hyphen before returning.</p>
+
+<pre class="brush: js">function styleHyphenFormat(propertyName) {
+ function upperToHyphenLower(match, offset, string) {
+ return (offset ? '-' : '') + match.toLowerCase();
+ }
+ return propertyName.replace(/[A-Z]/g, upperToHyphenLower);
+}
+</pre>
+
+<p>Given <code>styleHyphenFormat('borderTop')</code>, this returns 'border-top'.</p>
+
+<p>Because we want to further transform the <em>result</em> of the match before the final substitution is made, we must use a function. This forces the evaluation of the match prior to the {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}} method. If we had tried to do this using the match without a function, the {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}} would have no effect.</p>
+
+<pre class="brush: js">var newString = propertyName.replace(/[A-Z]/g, '-' + '$&amp;'.toLowerCase()); // won't work
+</pre>
+
+<p>This is because <code>'$&amp;'.toLowerCase()</code> would be evaluated first as a string literal (resulting in the same <code>'$&amp;'</code>) before using the characters as a pattern.</p>
+
+<h3 id="將華氏溫度置換成攝氏溫度">將華氏溫度置換成攝氏溫度</h3>
+
+<p>The following example replaces a Fahrenheit degree with its equivalent Celsius degree. The Fahrenheit degree should be a number ending with F. The function returns the Celsius number ending with C. For example, if the input number is 212F, the function returns 100C. If the number is 0F, the function returns -17.77777777777778C.</p>
+
+<p>The regular expression <code>test</code> checks for any number that ends with F. The number of Fahrenheit degree is accessible to the function through its second parameter, <code>p1</code>. The function sets the Celsius number based on the Fahrenheit degree passed in a string to the <code>f2c()</code> function. <code>f2c()</code> then returns the Celsius number. This function approximates Perl's <code>s///e</code> flag.</p>
+
+<pre class="brush: js">function f2c(x) {
+ function convert(str, p1, offset, s) {
+ return ((p1 - 32) * 5/9) + 'C';
+ }
+ var s = String(x);
+ var test = /(-?\d+(?:\.\d*)?)F\b/g;
+ return s.replace(test, convert);
+}
+</pre>
+
+<h3 id="利用行內函式及正則表示式來避免使用_for_迴圈">利用行內函式及正則表示式來避免使用 <code>for</code> 迴圈</h3>
+
+<p>The following example takes a string pattern and converts it into an array of objects.</p>
+
+<p><strong>Input:</strong></p>
+
+<p>A string made out of the characters <code>x</code>, <code>-</code> and <code>_</code></p>
+
+<pre>x-x_
+x---x---x---x---
+x-xxx-xx-x-
+x_x_x___x___x___
+</pre>
+
+<p><strong>Output:</strong></p>
+
+<p>An array of objects. An <code>'x'</code> denotes an <code>'on'</code> state, a <code>'-'</code> (hyphen) denotes an <code>'off'</code> state and an <code>'_'</code> (underscore) denotes the length of an <code>'on'</code> state.</p>
+
+<pre class="brush: json">[
+ { on: true, length: 1 },
+ { on: false, length: 1 },
+ { on: true, length: 2 }
+ ...
+]
+</pre>
+
+<p><strong>Snippet:</strong></p>
+
+<pre class="brush: js">var str = 'x-x_';
+var retArr = [];
+str.replace(/(x_*)|(-)/g, function(match, p1, p2) {
+ if (p1) { retArr.push({ on: true, length: p1.length }); }
+ if (p2) { retArr.push({ on: false, length: 1 }); }
+});
+
+console.log(retArr);
+</pre>
+
+<p>This snippet generates an array of 3 objects in the desired format without using a <code>for</code> loop.</p>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">規範</th>
+ <th scope="col">狀態</th>
+ <th scope="col">註解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.2.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.4.11', 'String.prototype.replace')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.replace', 'String.prototype.replace')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.replace', 'String.prototype.replace')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p class="hidden">本相容性表格使用結構化資料自動產生。想要貢獻的話,請看看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 並發個 PR。</p>
+
+<p>{{Compat("javascript.builtins.String.replace")}}</p>
+
+<h2 id="Firefox-specific_notes">Firefox-specific notes</h2>
+
+<ul>
+ <li>Starting with Gecko 27 {{geckoRelease(27)}}, this method has been adjusted to conform with the ECMAScript specification. When <code>replace()</code> is called with a global regular expression, the {{jsxref("RegExp.lastIndex")}} property (if specified) will be reset to <code>0</code> ({{bug(501739)}}).</li>
+ <li>Starting with Gecko 39 {{geckoRelease(39)}}, the non-standard <code>flags</code> argument is deprecated and throws a console warning ({{bug(1142351)}}).</li>
+ <li>Starting with Gecko 47 {{geckoRelease(47)}}, the non-standard <code>flags</code> argument is no longer supported in non-release builds and will soon be removed entirely ({{bug(1245801)}}).</li>
+ <li>Starting with Gecko 49 {{geckoRelease(49)}}, the non-standard <code>flags</code> argument is no longer supported ({{bug(1108382)}}).</li>
+</ul>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.match()")}}</li>
+ <li>{{jsxref("RegExp.prototype.exec()")}}</li>
+ <li>{{jsxref("RegExp.prototype.test()")}}</li>
+</ul>
diff --git a/files/zh-tw/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/zh-tw/web/javascript/reference/global_objects/string/tolowercase/index.html
new file mode 100644
index 0000000000..35b9dc71bc
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/string/tolowercase/index.html
@@ -0,0 +1,77 @@
+---
+title: String.prototype.toLowerCase()
+slug: Web/JavaScript/Reference/Global_Objects/String/toLowerCase
+translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>toLowerCase()</code></strong> 函式会回传将字符串转换为英文小写字母后的结果。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/string-tolowercase.html")}}</div>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><code><var>str</var>.toLowerCase()</code></pre>
+
+<h3 id="回传值">回传值</h3>
+
+<p>回传一组将原字串英文内容转换成英文小写字母后的结果。</p>
+
+<h2 id="描述">描述</h2>
+
+<p>The <code>toLowerCase()</code> 函式会回传一组将原字符串英文内容转换成英文小写字母后的结果。 <code>toLowerCase()</code> 并不会影响到原字符串 <code>str</code> 的内容值。</p>
+
+<h2 id="范例">范例</h2>
+
+<h3 id="使用toLowerCase()">使用<code>toLowerCase()</code></h3>
+
+<pre class="brush: js">console.log('ALPHABET'.toLowerCase()); // 'alphabet'
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">注解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.0.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.4.16', 'String.prototype.toLowerCase')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器相容性">浏览器相容性</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.String.toLowerCase")}}</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li>
+ <li>{{jsxref("String.prototype.toLocaleUpperCase()")}}</li>
+ <li>{{jsxref("String.prototype.toUpperCase()")}}</li>
+</ul>