How to convert multiple <br/> tags to a single <br/> tag using RegEx in Scala

1 Answer

0 votes
object NormalizeBrTags {
  def main(args: Array[String]): Unit = {
    var input = "ab<br/><br/>cd<br/>efg<br/><br/><br/>hijk<br/><br/>"

    // Replace consecutive <br/> (with optional spaces) with a single <br/>
    input = input.replaceAll("""(<br\s*/?>\s*)+""", "<br/>")

    println(input)
  }
}
 
 
 
/*
run:
 
ab<br/>cd<br/>efg<br/>hijk<br/>
 
*/
 

 



answered Jul 15, 2025 by avibootz
...