Skip to content
Advertisement

Delete anything between “<” and “>” in a String

I have try restString = restString.replaceAll("\&lt;.*\&gt;", "");

and

restString = restString.replaceAll("\&lt;[^(\&gt)]*\&gt;", "");.

Both seems don’t work. I don’t know if I could represent the meaning in the regular expression.

Advertisement

Answer

Make your regex non-greedy:

restString = restString.replaceAll("(?s)&lt;.*?&gt;", "");

Also I used (?s) to make dot match newlines as well.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement