15.5.4.12 String.prototype.seach(regexp)

2010-07-10

int String.prototype.search(regexp:regexp|mixed)

Search this string for the first occurrence of the regular expression. It's basically indexOf with a regular expression.

This is coerced to a string. If regexp is not a regular expression (an object whose [[Class]] is "RegExp"), a new RegExp(regexp) will be used as regular expression.

Code: (Meta Ecma)
String.prototype.seach = function(regexp){
CheckObjectCoercible(this);
var string = ToString(this);
if (Type(regexp) == "Object" && regexp.[[Class]] == "RegExp") var rx = regexp;
else var rx = new RegExp(regexp);
// cheat, todo: improve
return string.seach(rx);
}