Q:

Remove all  just before closing 

I would like to remove any <br> tag which comes up just before a closing </p> tag.
For example this is ok :
<p>Bla bla bla <br>
bla bla
</p>

But this is NOT ok :
<p>Bla bla bla <br>
</p>

In other words, every time I have :
<br> + white space or tab or new line or whatever providing no content + </p> 

Then, I want to remove that <br>.
How would this be achieved with javascript Regex ? (or any other javascript way)

A:

Try this one:
Iterate through each p,
get its html (not text, in order to get the <br> element),
replace the <br> with empty string using regex (one that matches <br> just before the </p>),
replace the original with the updated html.  
$('p').each(function(){
    var p = $(this);

    p.html(p.html().replace(/(<br)\s?\/?>\s?$/g,''));    

});

REGEX:
/(<br)\s?\/?>\s?$/g matches: <br>, <br/>, <br />, <br >

