JavaScript Symbol match Property
Last Updated :
19 May, 2023
JavaScript Symbol match property is used to identify the matching of a regular expression against a string and this function is called using String 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.
Below examples illustrate the JavaScript Symbol match Property:
Example 1: In this example, we will check if a string starts with a particular expression defined in regexp
javascript
const regexp1 = /geeksforgeeks/;
regexp1[Symbol.match] = false ;
console.log( '/geeks/' .startsWith(regexp1));
console.log( '/geeksforgeeks/' .endsWith(regexp1));
|
Output:
false
true
Example 2: In this example, we will pass a regular expression and see the type of error returned.
javascript
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
We have a complete list of Javascript symbols’ properties and methods, to check those please go through the Javascript Symbol Complete Reference article.