String.prototype.match() | javascript match regex
Thematch()methodretrievesthematcheswhenmatchingastringagainstaregularexpression.Parameters[1]regexp一個正規表達式的物件。若傳入一個非正規表達式的物件obj,則會視為傳入newRegExp(obj)。若只呼叫match()而沒有傳入任何參數,則會回傳內含一個空字串的陣列,即[""]。Returnvalue[2]Ifthestringmatchestheexpression,itwillreturnanArray[3]containingtheentirematchedstringasthefirstelement,followedbyanyresultscapturedinparentheses.Iftherewerenomatches,null[4]isreturned.Iftheregularexpressiondoesnotincludethegfl...
The match() method retrieves the matches when matching a string against a regular expression.
Parameters[1]regexp一個正規表達式的物件。 若傳入一個非正規表達式的物件obj,則會視為傳入 new RegExp(obj)。若只呼叫match()而沒有傳入任何參數,則會回傳內含一個空字串的陣列,即[""]。
Return value[2]If the string matches the expression, it will return an Array[3] containing the entire matched string as the first element, followed by any results captured in parentheses. If there were no matches, null[4] is returned.
If the regular expression does not include the g flag, str.match() will return the same result as RegExp.exec() (en-US)[5]. The returned Array[6] has an extra input property, which contains the original string that was parsed. In addition, it has an index property, which represents the zero-based index of the match in the string.
If the regular expression includes the g flag, the method returns an Array[7] containing all matched substrings rather than match objects. Captured groups are not returned. If there we...