I want to use this function but preserving the uppercase or lowercase so for example having something like
var value = 'Replace a string';
var search = 'replace';
value.replace(search, "<span style='font-weight: bold'>"+search+'<span>');
And the output of value be:
Replace a string
Since you're leaving the word itself as-is, you can use a simple regex:
var value = 'Replace a string';
var search = /replace/i;
value = value.replace(search, "<span style='font-weight: bold'>$&</span>");
The $&
indicates the matched pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With