JavaScript | Symbol.match Property

The Symbol.match property in JavaScript is a well-known symbol which is used to identify the matching of a regular expression against a string and this function is called using String.prototype.match() method.

Syntax:

regexp[Symbol.match] = false;

Parameters: It does not accept any parameters.

Return value: It will return the Boolean value for a string matching if matches found then it will return true otherwise returns false.

Below examples illustrate the Symbol.match property in JavaScript:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

    
const regexp1 = /geeksforgeeks/;
  
regexp1[Symbol.match] = false;
  
document.write('/geeks/'.startsWith(regexp1));
document.write('/geeksforgeeks/'.endsWith(regexp1));

chevron_right


Output:

false
true

Example 2: This example returns the TypeError.

filter_none

edit
close

play_arrow

link
brightness_4
code

    
reg[Symbol.match] = false;  
  
console.log('/bar/'.startsWith(/bar/));  

chevron_right


Output:

Error: First argument to String.prototype.startsWith must not be a regular expression.

Supported Browsers: The browsers supported by Symbol.match property are listed below:

  • Google Chrome 51
  • Firefox 50
  • Edge 15
  • Opera
  • Apple Safari

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.