本文介绍了如何通过正则表达式删除带引号的单个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个属性匹配到我可以进行搜索/替换.我遇到了麻烦,因为它匹配超出了我想要的属性的引号.例如,我想从这里删除 xref="...":
I am trying to match an attribute to I can do a search/replace. I am having trouble though because it is matching beyond the quotes of the attribute I want. For example, I want to remove xref="..." from here:
<a href="page.ashx" xref="somethingelse" title="something" class="image">
但是当我执行这样的 RegEx 时:xref=\".*\",然后它会选择属性外部参照、标题和类.我如何告诉它只选择外部参照属性?
But when I do a RegEx like this: xref=\".*\", then it selects the attributes xref, title, AND class. How do I tell it to only select the xref attribute?
推荐答案
我强烈建议使用正则表达式以外的东西来修改标记,但是,这应该有效:
I strongly suggest using something other than regex for modifying markup, however, this should work:
xref="[^"]*"
这篇关于如何通过正则表达式删除带引号的单个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!