Standard built-ins

String.prototype.search()

Try the free JavaScript compiler

Returns the first match index, or -1. Ordinary regex search disregards previous lastIndex for the search and restores it afterward.

Formal Syntax & Structure

javascript syntaxjavascript
text.search(regexp)

Parameters & Attributes

NameTypeDescription
regexpRegExp | StringPattern or convertible pattern.

Return Value

Number

Match index or -1.

Working Example

Example Snippetjavascript
console.log("abc".search(/b/));
JavaScript Reference