正则表达式:删除HTML中的特定样式属性

时间:2022-06-03 09:58:23

I have a problem in regex.

我在正则表达式中有问题。

I want to remove attribute style html backgroud-image in tag HTML, like this:

我想在标记HTML中删除属性样式html backgroud-image,如下所示:

<span style="background-image:   url ("http://mantis.we.intern/custom/userfiles/image/6y0eC4vzptnIxsikHs0AJA.png"); bgcolor:'red'">11111<br />
<span style="background-image: url('https:// asd asdmantis.we.intern/custom/userfiles/image/6y0eC4vzptnIxsikHs0AJA.png')">22222
<span style="background-image:url('https://fmantis.we.intern/custom/userfiles/image/6y0eC4vzptnIxsikHs0AJA.png')">3333
<span style="background-image:url( 'https://fmantis.we.intern/custom/userfiles/image/6y0eC4vzptnIxsikHs0AJA.png')">444
<span style="background-image:   url ( "http://mantis.we.intern/custom/userfiles/image/6y0eC4vzptnIxsikHs0AJA.png");">555<br />
<span style="background-image: url(xx https://trk.workexpert.net/web/include/ckeditor_432/plugins/icons.png?t=E0LB& xx); >666

And the result from regex, could be like this:

正则表达式的结果可能是这样的:

<span style=" bgcolor:'red'">11111<br />
<span style="">22222
<span style="">3333
<span style="">444
<span style="">555<br />
<span style=" >666

Thank you, before.

谢谢你,之前。

1 个解决方案

#1


2  

This regex does exactly what you need:

这个正则表达式正是你所需要的:

background-image:[^)]*[)];?

It selects the words background-image: and then everything up until the first ) with an optional ;

它选择单词background-image:然后选择一直到第一个)并带有一个可选项;

Regex101 Tested

#1


2  

This regex does exactly what you need:

这个正则表达式正是你所需要的:

background-image:[^)]*[)];?

It selects the words background-image: and then everything up until the first ) with an optional ;

它选择单词background-image:然后选择一直到第一个)并带有一个可选项;

Regex101 Tested