Ad

Removing Quotes Around Specific Substrings

- 1 answer

How would I remove double quotes from all attributes of HTML elements using regular expressions in javascript? I tried the regex provided in this thread: Regex to remove quotes around attributes when possible

It works for most attributes, but if I have an anchor tag with an href like "page2.html" or "page2.html#someid" it doesn't remove the quotes.

Thanks

Ad

Answer

You can use this:

var aString="\"abcde\""; //where this is yout variable 

and then

aString.replace(/"/g,"");

and you'll have all your quotes replaced

EDIT

The first parameter of the Replace function can be a Regular Expression

Ad
source: stackoverflow.com
Ad