Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Match Words Starts or Ends with a Pattern Using Regular Expression</title> </head> <body> <script> let regex = /(\bcar\w*)/g; let str = "Words begining with car: cart, carrot, cartoon. Words ending with car: oscar, supercar."; let replacement = '<b>$1</b>'; // Highlights the words beginning with car in bold let result = str.replace(regex, replacement); document.write(result); </script> </body> </html>