Last active
January 2, 2016 12:59
-
-
Save mcy/8306874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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