esmith Posted September 27, 2010 Posted September 27, 2010 I want to replace ampersands with the corresponding HTML code in my data. When I try to use the following regular expression: return data.replace(/&(\w+);/g, "&$1"); it works great for: var data = M&M; //returns M&M but including a parenthesis alters my output: var data = M&M(R); //returns M I tried swapping the \w with a \S but that yielded the same result. Can anyone suggest how I need to modify my expression so that the latter value correctly returns as: // M&M(R) (I considered using NormalizeEntities(), but that converts the embedded tags to HTML code as well which is a problem.)
esmith Posted September 28, 2010 Author Posted September 28, 2010 return data.replace(/&(\S+);/g, "&$1"); seems to work. I thought I tried that last night, but I must have been tired...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.