Reputation: 834
What is the regex for the HTML encoded version of <br />
in JavaScript: <br />
var edit_text = $(".edit_area").html().trim(),
regex = /<br\s*[\/]?>/gi; //This needs replacing
$(".edit_area").html(edit_text.replace(regex, "\n"));
Upvotes: 2
Views: 1539
Reputation: 149050
Your pattern won't match encoded <br>
elements because it has a plain <
which doesn't match an encoded <
. Try this to handle html encoded elements:
regex = /<br\s*\/?(>|>)/gi;
Note that the closing character of a tag doesn't have to be encoded, so my pattern handles allows either encoded (>
) or un-encoded (>
) closing characters. You can extend this to handle both using a pattern like this:
regex = /(<|<)br\s*\/?(>|>)/gi;
You can test it out here.
Upvotes: 3