JavaScript String search() MethodThe JavaScript string search() method is used to search the regular expression in the given string. This method returns -1, if match is not found. SyntaxThe search() method is represented by the following syntax: Parameterregexp - It represents the regular expression which is to be searched. ReturnThe position of searched character. JavaScript String search() Method ExampleLet's see some examples of search() method. Example 1Let's see a simple example to search for a string. Test it NowOutput: 16 Example 2In this example, we will see that search() method is case-sensitive. Test it NowOutput: 36 Example 3We can ignore case-sensitive behaviour of search() method by using ignore flag. Let's understand with the help of example: Test it NowOutput: 16 Example 4In this example, we will search a regular expression which is not present in the given string. Test it NowOutput: -1 Next TopicJavaScript String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India