Skip to content
Related Articles

Related Articles

JavaScript | Symbol.match Property
  • Last Updated : 25 Mar, 2020

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:




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

Output:

false
true

Example 2: This example returns the TypeError.




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

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
Recommended Articles
Page :