String.search() (Method)

Searches a string using a regular expression.

Availability:

ECMAScript edition - 3
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Property/method value type:Number primitive
JavaScript syntax:-myObject.search()
Argument list:aPatternA regular expression pattern

This is one of the additions to the String object to support regular expressions.

The character location where the match occurred is returned. If there is no match then the value -1 is returned instead.

If you use the global attribute ('g'), then it will be ignored.

Warnings:

Example code:

   myString = "JavaScript is good";
   myResult = myString.search(/GOOD/i);
   document.write(myResult);

See also:RegExp pattern, RegExp.exec(), RegExp.lastIndex, Regular expression, String.match(), String.replace(), String.split()

Cross-references:

ECMA 262 edition 3 - section 15.5.4.12