Executes the search for a match between a regular expression and this String object.
Method of String
Syntax
search( regexp )
Parameters
Parameter | Description |
---|---|
regexp | Name of the regular expression. It can be a variable name or a literal. |
Description
If successful, search returns the index of the regular expression 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 String.match (similar to the regular expression exec method).
Example
The following example prints a message which depends on the success of the test.