The well-known symbol specifies the method that returns the index within a string that matches the regular expression. This function is called by the method.

For more information, see RegExp.prototype[@@search]() and

Try it

Property attributes of
Writable no
Enumerable no
Configurable no


class caseInsensitiveSearch {
  constructor(value) {
    this.value = value.toLowerCase();
  [](string) {
    return string.toLowerCase().indexOf(this.value);

console.log('foobar'.search(new caseInsensitiveSearch('BaR')));
// expected output: 3


ECMAScript Language Specification

Browser compatibility

BCD tables only load in the browser

See also