I have got the following problem. I want to delete all substrings which start with < and end with >, except the substring <back>.
Example: <apps> <up> <down> <capital> ... should be deleted, but not <back>.
I am sure this works with RegExp and String.replace(), but I don't know how.
Currently, I have figured out this:
line = line.replaceAll("<[^<]*>", "");
The problem is, that this also deletes the <back>-substring!
I hope someone of you knows a solution.
Thank's for help!
you can use (?!<back>)<[^<]*> , line = line.replaceAll("(?!<back>)<[^<]*>", "");
(?!<back>) (negative look ahead) do not match the tag <back>
RegEx Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With