Executes the search for a match between a regular expression and this String object.
String
search(regexp)
regexp
Name of the regular expression. It can be a variable name or a literal.
If successful, search returns the index of the match inside the string. Otherwise, it returns -1.
When you want to know whether a pattern is found in a string use search (similar to the regular expression test method); for more information (but slower execution) use match (similar to the regular expression exec method).
The following example prints a message which depends on the success of the test.