![]() |
VOOZH | about |
The search() method is an inbuilt function in TypeScript that is used to search for a match between a regular expression and a string. It returns the index of the first match, or -1 if no match is found.
string.search(regexp);This methods accept a single parameter as mentioned above and described below:
Return Value:
In this example, we use the search() method to find the position of a substring that matches a regular expression.
Output:
Found at index: 7In this example, we use the search() method to look for a substring that does not exist in the string.
Output:
Not Found