Javascript String Replace - RegEx for Non-Alphanumeric Characters Like Backslash, Greater Than, etc -
i have string serialized dom world , want find closing tags in string , replace them new string. never know length of original string, character counts etc. not work here. sample scenario:
var onetext = "</content><tag>a whole bunch of stuff</tag></message>" var twotext = "</content><tag>a whole bunch of new, unrelated stuff</tag></message>" var threetext = onetext.replace(/[\/<]/\\/content>.+</message>/,"</content>"+twotext+"</message>"); i don't have regular expressions right find these instances of backslash, greater-than or less-than. welcome anyone's in getting run correctly. thanks.
apparently, there way 1 line
you can use grouping identifiers in replacements string this:
'<foo>some data</foo>'.replace(/(<foo>)(.+)(<\/foo>)/,'<bar>$2</bar>') however, @ end of day, if want replace closing tags, replace those, don't worry rest of content, unless need pass through well. if looking @ ... expression need:
/<\/content>.+<\/message>/
Comments
Post a Comment