Match-1

 

JavaScript match() function return an array by searching a string for a match against a regular expression.. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="matchString()">Show the matched string</button> <p id="sample"></p> <script> function matchString() { var str = "I love learnKode that keeps my learning of code so easy."; var result = str.match(/earn/g); document.getElementById("sample").innerHTML = result; } </script> </body> </html>
Output