Currently I have:
this.html(this.html().replace(/<\/?([i-z]+)[^>]*>/gi, function(match, tag) {
return (tag === 'p') ? match : '<p>';
return (tag === '/p') ? match : '</p>';
return (tag === 'script') ? match : 'script';
return (tag === '/script') ? match : '/script';
}));
However, the <p> and <script> tags are still being removed, what am I doing wrong?
Am pretty sure of this now, the regex doesnt work for closing tags, and only looking for i-z isnt catching the full tag.
Try the regex of:
/<\(/?[a-z]+)[^>]*>/gisomething odd happens with the code though when trying to return ‘<script>’ when matching script so in these cases maybe
return matchAndy E’s head’s suggestion of changing the if statement structure I think helps too, the main thing is the
or even do this as a default instead of specifically looking for p and script tags, it will return the match value of the matched tag if no if statement is met.
Code I wrote for testing: