JavaScript match() Function | jquery string regex match
Thestring.match()isaninbuiltfunctioninJavaScriptusedtosearchastringforamatchagainstanyregularexpression.Ifthematchisfound,thenthiswillreturnthematchasanarray. Syntax: string.match(regExp)Parameters:Heretheparameteris“regExp”(i.e.regularexpression)whichwillcomparewiththegivenstring. ReturnValue:ItwillreturnanarraythatcontainsthematchesoneitemforeachmatchorifthematchwillnotfoundthenitwillreturnNull. JavaScriptcodetoshowtheworkingofmatch()function: Example1: Input: varstring=Welcometogeek...
The string.match() is an inbuilt function in JavaScript used to search a string for a match against any regular expression. If the match is found, then this will return the match as an array. Syntax:
string.match(regExp)Parameters: Here the parameter is “regExp” (i.e. regular expression) which will compare with the given string. Return Value: It will return an array that contains the matches one item for each match or if the match will not found then it will return Null. JavaScript code to show the working of match() function: Example 1:
Input: var string = Welcome to geeks for geeks! document.write(string.match(/eek/g); Output: eek, eekIn the above example, substring “eek” will match with the given string, and when a match is found, it will return an array of string objects. Here “g” flag indicates that the regular expression should be tested against all possible matches in a string. code #1:
javascript<script>