简体   繁体   English

如何使用正则表达式从样式属性中删除内部引号

[英]How to remove inner quotes from the style attribute using regEx

I need to remove all inner quotes from style attribute:我需要从 style 属性中删除所有内部引号:

<span style="color: rgb(34 , 34 , 34) ; font-family: "arial" , "verdana" , "helvetica" , sans-serif ; font-size: 15.33px ; font-weight: normal" >

What I need:我需要的:

<span style="color: rgb(34 , 34 , 34) ; font-family: arial , verdana , helvetica , sans-serif ; font-size: 15.33px ; font-weight: normal" >

We can have multiple style tags into our content.我们可以在我们的内容中添加多个样式标签。 What is the simplest way to solve it?解决它的最简单方法是什么?

You could use references to take care of spaces/punctuation.您可以使用引用来处理空格/标点符号。 In python this should cover a fair amount of cases:在 python 中,这应该涵盖相当多的情况:

import re
xmlstr = """<span style="color: rgb(34 , 34 , 34) ; font-family: "arial" , "verdana" , "helvetica" , sans-serif ; font-size: 15.33px ; font-weight: "normal"" >"""
newstr = re.sub(r'(\s?)\"(\w*)\"(\s?)([,\"])', r'\1\2\3\4', xmlstr)
print(newstr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM