Skip to content
Advertisement

How to remove characters between two specific characters in a String?

How to remove characters between two specific characters in a String?

Example:

Original String: "Hello <>Remove this String<> how are you?"

Modified String: "Hello <><> how are you?"

Advertisement

Answer

You can use regex like this:

String result = original.replaceAll("<>.*<>", "<><>");

Output:

Hello <><> how are you?

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