JavaScript String search() MethodLast Updated : 17 Mar 2025 The 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. Output: 16 Example 2In this example, we will see that search() method is case-sensitive. Output: 36 Example 3We can ignore case-sensitive behaviour of search() method by using ignore flag. Let's understand with the help of example: Output: 16 Example 4In this example, we will search a regular expression which is not present in the given string. Output: -1 Next TopicJavaScript String |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India