Reputation: 6125
I am trying to perform a cleaning of a HTML text, and I want to replace multiple occurrencies of
with a single occurrence of it.
So, for example:
<o:p> </o:p></b></p>
should become
<o:p> </o:p></b></p>
despite the number of
s, that could vary.
I could use a replace()
in a loop, repeating until the result varies. But I think there could exist a one-linear or at least a smarter method.
Upvotes: 0
Views: 141
Reputation:
String has a second method to replace substrings besides the standard replace
that takes a regular expression as an argument called replaceAll
. (*)
With that method you can easily do it with a simply
.replaceAll("( )+", " ")
(*) That those 2 method are really badly named and often confuse beginners is a very well known weakness of java/the String class.
Upvotes: 1