Highlight substring in line of text with JavaScript!
by landro
The
replace()
method returns a new string with some or all matches of apattern
replaced by areplacement
. Thepattern
can be a string or aRegExp
, and thereplacement
can be a string or a function to be called for each match. Ifpattern
is a string, only the first occurrence will be replaced.The original string is left unchanged.
See the Pen Highlight Strings with JavaScript by adhocracy (@adhocracy) on CodePen.