如何使用正则表达式从内联样式中删除样式元素? [英] How do I remove a style element from an inline style using regex?
本文介绍了如何使用正则表达式从内联样式中删除样式元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从内联样式中只删除一个属性, float
及其值。我想从这开始:
I am trying to remove only one property, float
, and its value, from an inline style. I would like to start with this:
<div id="first_line_info" style="width:490px; float:right;"> </div>
让它像这样:
And make it like this:
<div id="first_line_info" style="width:490px"> </div>
到目前为止,我已经试过这段代码:
So far I have tried this code:
Regex noInlineStylePattern = new Regex("style=\"[^\"]*\"", RegexOptions.IgnoreCase);
data = noInlineStylePattern.Replace(data, "");
这将删除所有内联样式。 ?
This removes all of the inline styles. How can I just remove the float?
推荐答案
这应该会移除所有的浮点数:
This should remove all floats:
data = Regex.Replace(data, @"(style=\"".*?)(float:\s*[^;\""]+;?)(.*?\"")", "$1$3", RegexOptions.IgnoreCase)
这篇关于如何使用正则表达式从内联样式中删除样式元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文