User:Michael Anon/custombrcorrector.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function autoEdCustombrCorrector(str) {
  str = str.replace(/<+[^<>a]{0,3}br[^\/<>]{0,3}>+/gim, '<br>');
  str = str.replace(/<+[^<>a]{0,3}br[^<>]{0,3}\/[^<>]{0,3}>+/gim, '<br />');
  if (str.match(/<br>/g) && str.match(/<br \/>/g))
  {
    if (str.match(/<br>/g).length > str.match(/<br \/>/g).length)
      {str = str.replace(/<br \/>/g, '<br>');}
    else 
      {str = str.replace(/<br>/g, '<br />');}
  }
  return str;
}