javascript - Regex replace unterminated parenthetical -
i want replace unnecessary breaks in string. have written regex replace throws error: syntaxerror: unterminated parenthetical
var str = "<h1>sdflk</h1><br><br><br><br><p>test</p><br><br><br><br>"; str.replace(/((</[a-za-z0-9]+>)(<br>)+)/,"\$2"); but don't see missing parenthese.
you must add \ before / in re:
/((<\/[a-za-z0-9]+>)(<br>)+)/ another option use regexp:
re = new regexp("((</[a-za-z0-9]+>)(<br>)+)"); "<h1>sdflk</h1><br><br><br><br><p>test</p><br><br><br><br>".replace(re,"\$1");
Comments
Post a Comment