" to "
", using the Java method String.replaceAll (String, String)? how to convert...">

How to convert strings, for example, "<br> <br> <br> <br> <br>" to "<br>", using the Java method String.replaceAll (String, String)?

how to convert a string

"<br><br><br><br><br><br>" to "<br>" using java String.replaceAll(String, String) method? 

I tried both:

  str.replaceAll("<br>+","<br>"); str.replaceAll("<br>{1,}","<br>); 

but does not work.

+4
source share
1 answer

<br>+ matches "<br>>>>>>>>" , try instead: (<br>)+

And if there are spaces between the tags, do:

 str = str.replaceAll("(<br>\\s*)+","<br>"); 
+10
source

Source: https://habr.com/ru/post/1412251/


All Articles