- String_Object: String to perform a search. JS Match function check for a portion of a string present in this String_Object
- RegExp: Valid string or Regular expression you want to match. If the specified substring is not in the string_object, the Match function will return NULL
The following set of examples will help you understand the string match function.
Following statement will search for ‘abc’ and return it. As you can see, ‘abc’ substring repeated thrice in Str2, but the Match String Function is returning the first occurrence
var Str3 = Str2.match("abc");
var Str4 = Str2.match(/abc/g);
From the above statement, you can observe that the term abc repeated many times. However, the JS Match function considers the string “ABC” is different from “abc” and “Abc”. Now, let us use the i regular expression along with string (i will perform the case insensitive string search.)
var Str6 = Str1.match(/abc/gi);