JS: String.prototype.search
str.search(regex_or_str)
-
Return the index of first char of matched string. If no match, returns
-1
.
If argument is string, it is converted to regex by RegExp
const x = "a 99 b"; // find digit console.log(x.search(/\d/) === 2); // true // using string as arg console.log(x.search("\\d") === 2); // true // not found console.log(x.search("ttt") === -1); // true
JavaScript, Regular Expression
- JS: RegExp Tutorial
- JS: Regex Functions
- JS: RegExp Syntax
- JS: RegExp Flag
- JS: Regex Replace String Dollar Sign
- JS: Regex Replace Function Args
- JS: RegExp Object
- JS: RegExp Constructor
- JS: RegExp.prototype
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.replaceAll
- JS: RegExp.prototype.test
- JS: RegExp.prototype.exec