JavaScript (ES2026) reference · String Methods

JavaScript String search() Method

Return the index of the first regular-expression match, or -1 if there is none.

JavaScript (ES2026) Since ES3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.search(regexp)

Parameters

ParameterDescription
regexp A regular expression.

Return value

An index, or -1.

Examples

Where is the first digit?Try it yourself
console.log("Invoice #4821".search(/\d/), "no digits".search(/\d/));

Output

9 -1
Case-insensitive searchTry it yourself
console.log("Hello World".search(/world/i));

Output

6

Version history

VersionChange
JavaScript ES3Added

Was this page helpful?