Skip to content

Instantly share code, notes, and snippets.

@mcy
Last active January 2, 2016 12:59
Show Gist options
  • Select an option

  • Save mcy/8306874 to your computer and use it in GitHub Desktop.

Select an option

Save mcy/8306874 to your computer and use it in GitHub Desktop.
private static final Pattern multipleChars = Pattern.compile("([a-zA-Z]+)(\1{2,})");
public static String cleanSpam(String spam){
Matcher matcher = multipleChars.matcher(spam);
if(!matcher.find())
return spam;
Set<String> chars = new HashSet<>();
do{
chars.add(matcher.group(1));
}while(matcher.find());
for(String s : chars){
spam = spam.replaceAll("(" + s + "){3,}" , s + s);
}
return spam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment