Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Find All Occurrences of a Pattern in a String Using Regular Expression</title> </head> <body> <script> let regex = /ca[kf]e/g; let str = "He was eating cake in the cafe."; let matches = str.match(regex); document.write("Found " + matches.length + " matches: " + matches); console.log(matches); </script> </body> </html>