I want to perform a "find and replace" operation on the text of certain elements stored in a jQuery object. I want to replace the text using the javascript function .replace(), which uses a regex selector. How to I correct this sample code?
$(JQUERY_OBJECT).html(
$(this).text().replace(/REGEX_EXPRESSION/, 'REPLACEMENT_TEXT')
);
Note: The jQuery objects I am manipulating may contain child elements, but I do not want to preserve them. That is why I am using .text(). If it is possible to run the .replace() function without discarding inner elements, though, that would be great.