Search code examples
javaregexpunctuation

How can i check that my particular string has general punctuations? and how to remove it from string?


public static void main(String args[]) {
    final StringBuilder builder = new StringBuilder();
    String input = "Autism: 'Weak “Central Coherence” in: II. Real-life and MMag. ? ? ? ö ü ä André Gazsó";
    final Pattern specialCharsForFieldContent = Pattern.compile("([-+\"!(){}\\[\\]^\\~\\: \\\\]|\\|\\||&&)");
    for (char c : input.toCharArray()) {
        Matcher m = specialCharsForFieldContent.matcher(input);
        if (Character.isLetterOrDigit(c) || m.find()) {
            builder.append(Character.isLowerCase(c) ? c : c);
        }
    }
    System.out.println(builder.toString());
}

here before central there is punctuation its not a double quotes. I want to remove it.

please refer below link:

http://www.charbase.com/block/general-punctuation for puntuations.


Solution

  • Try This:

    String words = input.replaceAll("[^a-zA-Z ]", "");