[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/search [Back]  [Original]

String.prototype.search() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String.prototype.search()

20157

search() String

const paragraph = "I think Ruth's dog is cuter than your dog!";

// Anything not a word character, whitespace or apostrophe
const regex = /[^\w\s']/g;

console.log(paragraph.search(regex));
// Expected output: 41

console.log(paragraph[paragraph.search(regex)]);
// Expected output: "!"

js
search(regexp)

regexp

Symbol.search

regexp RegExp Symbol.search new RegExp(regexp) RegExp

-1

String.prototype.search() Symbol.search RegExp.prototype[Symbol.search]()

regexp g search() lastIndex 0 search() RegExp.prototype[Symbol.search]()

search()

-1

js
const str = "hey JudE";
const re = /[A-Z]/;
const reDot = /[.]/;
console.log(str.search(re)); //  4J
console.log(str.search(reDot)); //  -1.

ECMAScript 2027 LanguageSpecification
# sec-string.prototype.search


Web Proxy Viewer  |  New URL  |  Original Page