I have searched alot but didn't find my specific case. I need a regex to match everything except what's written between two angle brackets:
I found how to match everything except angle brackets:
String regex="[^<>]*";
Or how to match the content between two angle brackets:
\<(.*?)\>
or <([^>]+)>
Which is fine however I need the excact opposite of that. I tried playing around with ^ (negate) but didn't have sucess.
For example:
Fara Foo <not be selected>;another <also not be selected>
should return: Fara Foo <>;another <>
The whole thing should work in java.
Update: A replaceAll(...)
solution does not help me since I want to use the regex in an replaceAll(...) call :-) So I really need the regex.
Since it was asked in a comment:
In java there there are certain string operations like replaceAll() or split() which directly take a regex. There is another way by using Pattern
and Matcher
. Its more convenient to use replaceAll()
instead of the pattern matcher. Thats why I want to use a "negative" regex to be able to use replaceAll...