Removing a substring between two characters (java)
I have a java string like this:
String string = "I <strong>really</strong> want to get rid of the strong-tags!";
And I want to remove tags. I have a few lines where the tags are longer, so I would like to find a way to remove all the "<>" characters, including these characters.
One way is to use the built-in string method, which compares the string against regEx, but I have no idea how to write them.
To avoid regex:
String toRemove = StringUtils.substringBetween(string, "<", ">");
String result = StringUtils.remove(string, "<" + toRemove + ">");
:
String[] allToRemove = StringUtils.substringsBetween(string, "<", ">");
String result = string;
for (String toRemove : allToRemove) {
result = StringUtils.remove(result, "<" + toRemove + ">");
}
Apache StringUtils null-, empty- match-