Symbol.match JavaScript JS

The JavaScript Symbol.match property looks for the matching of a regular expression against a string.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Symbol.match
Symbol.match
Symbol.match

Parameters:
string: It represents the string.

Returns:
It returns true if a regular expression matches against a string, otherwise, it returns true.

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var alpha = /HELLO WORLD/;
alpha[Symbol.match] = false;
document.write('/HELLO WORLD/'.startsWith(alpha));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var alpha = /HELLO WORLD/; alpha[Symbol.match] = false; document.write('/HELLO WORLD/'.startsWith(alpha)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
var alpha = /HELLO WORLD/;
alpha[Symbol.match] = false;
document.write('/HELLO WORLD/'.startsWith(alpha));
</script>
</body>
</html>

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
const regExp = /w3schools/;
regExp[Symbol.match] = false;
document.write('/w3schools/'.startsWith(regExp));
document.write("</br>");
document.write('/jai/'.endsWith(regExp));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> const regExp = /w3schools/; regExp[Symbol.match] = false; document.write('/w3schools/'.startsWith(regExp)); document.write("</br>"); document.write('/jai/'.endsWith(regExp)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
const regExp = /w3schools/;
regExp[Symbol.match] = false;
document.write('/w3schools/'.startsWith(regExp));
document.write("</br>");
document.write('/jai/'.endsWith(regExp));
</script>
</body>
</html>