Skip to content Skip to sidebar Skip to footer

Replacing Closing HTML Tags With HTML Tag + \n

I'm trying to replace generally closing html tags with the closing tag + a line break, i found similar posts here on SO, none really helped me to accomplish what I'm looking for. &

Solution 1:

You have to capture the regular expression with brackets, assign the replaced string and replace ${1} by $1:

var regex = new RegExp("(</.*?>)", "gi");

strContent = strContent.replace(regex, "$1 \n   ")
                       .replace(/\/>/g,'/> \n    ');

Or you can simply put the replace methods into the val function.


Post a Comment for "Replacing Closing HTML Tags With HTML Tag + \n"