JS uses rules to write a sentence to determine whether to repeat tags continuously.

for example, a string is

    

<br/><br><br/><br><br/><br><br/><br><br/><br>

how to write the rule replaces the final result of the string with

Hello,

I"m my brother. < br/ >

?

Jun.23,2022

let str = '

<br/><br><br/><br><br/><br><br/><br><br/><br>' str = str.replace(/(

<\/p>)*/g, '$1') str = str.replace(/(<br\/><br>)*/g, '$1')


var reg = /(<\/?([A-Za-z]+\/?)>)+/g;
str.replace(reg,'<$2></$2>');


var reg = /(<([a-zA-Z]+)\/?><\/?\2\/?>)\1{1,}/g;
var s = /(<hr\/?>)\1{1,}/g;
str.replace(reg,function(){
  var f = arguments[2];
  return (f=='br'?'<br/>':'<'+f+'></'+f+'>')
}); //
str = str.replace(s,'$1'); //hr
Menu