using Parenthesized Substring Matches

including parentheses in a regular expression pattern causes the corresponding submatch to be remembered. For example, /a(b)c/ matches the characters 'abc' and remembers 'b'. To recall these parenthesized substring matches, use the Array elements [1], ..., [n].

the number of possible parenthesized substrings is unlimited. The returned array holds all that were found. The following examples illustrate how to use parenthesized substring matches.

使用帶括號的子串匹配

在正則表達式模式中包含括號會導致記住相應的子匹配。

例如,/a(b)c/ 匹配字符 'abc' 並記住 'b'。 要調用這些帶括號的子字符串匹配項,請使用數組元素 [1], ..., [n]。

可能的括號子串的數量是無限的。 返回的數組包含所有找到的內容。

以下示例說明如何使用帶括號的子字符串匹配。

下面這個 script 以 replace() 方法移轉字串位置。對於要被置換的文字內容, 以 $1 和 $2 來代表先前 re 這個變數裡面,找出來綑綁且照順序來表示兩個子字串。