Standard built-ins
String.prototype.search()
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
| Name | Type | Description |
|---|---|---|
| regexp | RegExp | String | Pattern or convertible pattern. |
Return Value
Number
Match index or -1.
Working Example
Example Snippetjavascript
console.log("abc".search(/b/));