Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Match Strings Beginning with Specific Characters Using Regular Expression</title> </head> <body> <script> let regex = /^J/; let names = ["James Bond", "Clark Kent", "John Rambo"]; // Loop through names array and display matched names for(let name of names) { if(regex.test(name)) { document.write("<p>" + name + "</p>") } } </script> </body> </html>