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

查看:54
本文介绍了正则表达式要从任何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.

我正在使用Classic 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天全站免登陆