Jump to content

Regular Expression Problem


esmith

Recommended Posts

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.)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...