public static String unifyTerminators ( String text ) { text = text . replaceAll ( "[\",:;()\\-]+" , " " ) ; // Replace commas, hyphens, quotes etc (count them as spaces) text = text . replaceAll ( "[\\.!?]" , "." ) ; // Unify terminators text = text . replaceAll ( "\\.[\\. ]+" , "." ) ; // Check for duplicated terminators text = text . replaceAll ( "\\s*\\.\\s*" , ". " ) ; // Pad sentence terminators return text . trim ( ) ; }
Replaces all terminators with space or dots . The final string will contain only alphanumerics and dots .