.search()
Published Jun 23, 2021Updated Jun 19, 2023
Contribute to Docs
Takes a regular expression argument and returns either the character position of the start of the first matching substring or -1
if there is no match.
Syntax
string.search(regularExpression);
Example
Find the starting index of the substring match for our regular expression:
const programmingLanguage = 'JavaScript';console.log(programmingLanguage.search(/java/i));// Output: 0
Codebyte Example
The following is runnable, and demonstrates the use of the `.search()’ method:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.