The JavaScript Symbol.match serves the purpose of determining whether a regular expression corresponds with a given string.
Syntax
Example
Symbol.match
Parameters
String
Return value
Return true if a string matches otherwise false.
Browser Support
| Chrome | 32 |
|---|---|
| Safari | 8 |
| Firefox | 29 |
| Opera | 19 |
Example 1
Example
<script>
//JavaScript to illustrate Symbol.match
var reg = /example/;
reg[Symbol.match] = false;
// check string start with hello
document.write('/example/'.startsWith(reg));
// check string ends with hi
document.write("<br>");
document.write('/we/'.endsWith(reg));
//expected output: true
// false
</script>
Output:
Output
True
False
Example 2
Example
<script>
//JavaScript to illustrate Symbol.match
var reg = /Java123/;
reg[Symbol.match] = false;
// check string start with qw
document.write('/qw/'.startsWith(reg));
// check string ends with 34
document.write("<br>");
document.write('/34/'.endsWith(reg));
//expected output: false
// false
</script>
Output:
Output
false
false