how can I replace everything between two strings(including the strings themself) in Java?
it would look something like this: String string = text text text text text <!-- Begin Sequence text text text --> tex text text text <!-- text text text --> text text text <!-- Begin Sequence text text text -->;
I only want to delete parts that start with: <!-- Begin Sequence ... ->, but keep parts that dont contain "Begin Sequence": <!-- text text text ->.
I already tried to use .replaceAll("(?s)<!--.*?-->", "");
But it ends up deleting every '<!--' and '-->'...
Anybody got a solution to my problem? if you didnt understand what I was trying to say then please ask
Remember that Strings are not intended for replacement. Find yourself a StringBuilder, which you can create an object of using that String. Find the index of the String to its left and of the delimiter to its right and then you will have to work out how many characters to delete. You may be able to use a regular expression on the String to find the two delimiters.