I have this:
Title = Regex.Replace(Title, s, "<span style=\"background:yellow\">" + s + "</span>", RegexOptions.IgnoreCase);
Where s
is a word like facebook
. If the title is:
How to make a Facebook game
I would like to replaced to:
How to make a <span style="background:yellow">Facebook</span> game
Even if the search word is 'facebook' (note capitalisation). Basically, how do I retain the original capitalisation of the word?
Another example, search term FACEBOOK
, string Hello FaCeBoOk
is turned to Hello <span style="background:yellow">FaCeBoOk</span>
You can use the $&
substitution for that:
Regex.Replace(Title, s, "<span style=\"background:yellow\">$&</span>", RegexOptions.IgnoreCase)
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