正则表达式从任何 HTML 标记中删除 HTML 属性(样式 =“")? [英] Regex to remove HTML attribute from any HTML tag (style="")?

查看:21
本文介绍了正则表达式从任何 HTML 标记中删除 HTML 属性(样式 =“")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个正则表达式模式,它将在 HTML 标记中查找属性.具体来说,我想找到...的所有实例

I'm looking for a regex pattern that will look for an attribute within an HTML tag. Specifically, I'd like to find all instances of ...

style=""

... 并将其从包含它的 HTML 标记中删除.显然,这也包括双引号中包含的任何内容.

... and remove it from the HTML tag that it is contained within. Obviously this would include anything contained with the double quotes as well.

我正在使用经典 ASP 来执行此操作.我已经为不同的正则表达式模式设置了一个函数设置,该模式在字符串中查找所有 HTML 标记并删除它们.它工作得很好.但现在我只需要另一种模式来专门删除所有样式属性.

I'm using Classic ASP to do this. I already have a function setup for a different regex pattern that looks for all HTML tags in a string and removes them. It works great. But now I just need another pattern for specifically removing all of the style attributes.

任何帮助将不胜感激.

推荐答案

我觉得这样可以:

/style="[a-zA-Z0-9:;.s()-,]*"/gi

如果您只想替换某些部分,也可以将它们放入捕获组中

You could also put these in capturing groups, if you wanted to replace some parts only

/(style=")([a-zA-Z0-9:;.s()-,]*)(")/gi

工作示例: http://regexr.com?2up30

这篇关于正则表达式从任何 HTML 标记中删除 HTML 属性(样式 =“")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆