public class StrippingUnwantedChars { public static void main(String[] args) { String s = "Good Morning, today is 1900-12-31."; /** * Replace characters that are NOT lowercase letters(a-z), uppercase * letters(A-Z) or numbers(0-9) with empty string. */ s = s.replaceAll("[^a-zA-Z0-9]", ""); System.out.println(s); // Output: GoodMorningtodayis19001231 } }