Search a string using regular expressions

Search with regular expression

search() accepts a regular expression as the argument.

search() method returns the index of the first pattern occurrence in the string. search() returns -1 if not found.

Example


var text = "loom, room, doom"; 
var pos = text.search(/asdf/); 
console.log(pos); //-1 

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window