I want to remove the jQuery attribute from the string. Please suggest the regex.
<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, "")
Or, if the characters after "jQuery" are not all digits:
str = str.replace(/\sjQuery[^=]+="[^"]*"/g, "")
/ at the beginning and the /g at the end of the expression in my answer is part of JS regex literal syntax and not part of the regular expression itself, so to test it at that site you have to just use \sjQuery\d+="[^"]*" (and set the global option).<a> tag, works out where it ends, does the replacing within that substring only, and then continues.I liked the following way of accomplishing this:
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);