I have a string that has non-alphanumeric characters, this string contains English and non English alphabets. I need to clean the string from non-alphanumeric characters, but I want to keep some of them. For instance: Let's say that I want to keep comma and colon only.
Example:
String st = "I, Love: ( Coding {}+-), codificación"
I want the output to be "I,Love:Coding,codificación"
Is there a regex that can do that?
Note the method below will clean the text from all non-alphanumeric characters.
public static String cleanText(String text) {
return text.replaceAll("\\P{LD}+", "");
}