What C# regular expression would 开发者_如何学Pythonreplace all of these:
<BR style=color:#93c47d>
<BR style=color:#fefefe>
<BR style="color:#93c47d">
<BR style="color:#93c47d ...">
<BR>
<BR/>
<br style=color:#93c47d>
<br style=color:#fefefe>
<br style="color:#93c47d">
<br style="color:#93c47d ...">
<br>
<br/>
with:
<br/>
basically "remove all attributes from any BR element and lowercase it".
Something like:
Regex.Replace(myString, "<br[^>]*>", "<br/>", RegexOptions.IgnoreCase);
Or without the IgnoreCase
:
Regex.Replace(myString, "<[Bb][Rr][^>]*>", "<br/>");
Assuming you never had any attributes after style, I would bet something like
class Program
{
const string SOURCE = @"<BR style=color:#93c47d>
<BR style=color:#fefefe>
<BR style=""color:#93c47d"">
<BR style='color:#93c47d'>
<BR>
<BR/>
<br style=color:#93c47d>
<br style=color:#fefefe>
<br style=""color:#93c47d"">
<br style='color:#93c47d'>
<br>
<br/>";
static void Main(string[] args)
{
const string EXPRESSION = @"(style=[^""'][^>]*)|(style=""[^""]*"")|(style='[^']*')";
var regex = new Regex(EXPRESSION);
Console.WriteLine(regex.Replace(SOURCE, string.Empty));
}
}
You might be better off with a programmatic solution if there are attributes written into a tag after the style attribute.
精彩评论