Highlight Matches

Wrap regex matches with HTML tags.

Code

General
str.replace(new RegExp(`(${pattern})`, 'gi'), '<mark>$1</mark>');

Parameters

String to search

Regex pattern

Browser·fetch() may be limited by CORS

More JavaScript Snippets