Reputation: 49
How to do a regex replace for this text:
<span style=\"text-decoration: underline;\">Request Block Host</span> to
`<u>Request Block Host</u>`
So far, I have this, assume "text" is the complete string that has the above tag.
text = Regex.Replace(text, "<span style=\"text-decoration: underline;\">.*?</span>", delegate(Match mContent)
{
return mContent.Value.Replace("<span style=\"text-decoration: underline;\">", "<u>").Replace("</span>", "</u>");
}, RegexOptions.IgnoreCase);
Upvotes: 0
Views: 541
Reputation: 149040
This should do the trick:
text = Regex.Replace(text,
"<span style=\"text-decoration: underline;\">(.*?)</span>",
"<u>$1</u>",
RegexOptions.IgnoreCase); // <u>Request Block Host</u>
This will match a literal <span style="text-decoration: underline;">
, followed by zero or more of any character, captured in group 1, followed by a literal </span>
. It will replace the matched text with <u>
, followed by the contents of group 1, followed by a literal </u>
.
Upvotes: 3
Reputation:
var _string = "<span style=\"text-decoration: underline;\">Request Block Host</span>";
var text = Regex.Replace(_string, "<.+>(.*)</.+>", "<u>$1</u>");
:D
Upvotes: 1