用于从<a>超链接

Regex for removing jQuery attribute from <a> hyperlinks

本文关键字:超链接 gt lt 用于      更新时间:2023-09-26

我想从字符串中删除jQuery属性。请建议正则表达式。

<A href="http://www.yahoo.com" jQuery1327469683587="77" jQuery1327470207412="14">yahoo</A><BR>
var str = '<A href="http://www.yahoo.com" jQuery1327469683587="77" jQuery1327470207412="14">yahoo</A><BR>'
str = str.replace(/'sjQuery'd+="[^"]*"/g, "")

或者,如果"jQuery"后面的字符不是全部数字:

str = str.replace(/'sjQuery[^=]+="[^"]*"/g, "")

我喜欢以下实现方式:

var inputText = "<A jQuery1327469683587='"77'" href='"http://www.yahoo.com'" jQuery1327470207412='"14>'">yahoo</A><BR><A jQuery1327469683587='"77'" href='"http://www.yahoo.com'" jQuery1327470207412='"14>'">yahoo</A><A jQuery1327469683587='"77'" href='"http://www.yahoo.com'" jQuery1327470207412='"14>'">yahoo</A><A jQuery1327469683587='"77'" href='"http://www.yahoo.com'" jQuery1327470207412='"14>'">yahoo</A>";
var matchedTags = inputText.match(/<a[^<>]+[^=]">/gi);     //Match all link tags
alert(matchedTags);
for(i = 0; i < matchedTags.length; i++) {
    var stringBeforeReplace = matchedTags[i];
    matchedTags[i] = matchedTags[i].replace(/'s+jQuery'w+="[^"]*"/g,"");
    inputText = inputText.replace(stringBeforeReplace, matchedTags[i]);
}
alert(inputText);