import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\b(?:a*(?:ha*){2,}h?)\\b|\\b(?:a*(?:ja*)+j?)\\b|\\b(?:e*(?:je*)+j?)\\b|\\b(?:i*(?:ji+)+j?)\\b|\\b(?:A*(?:JA+)+J?)\\b|\\b(?:A*(?:HA+)+H?)\\b|\\b(?:e*(?:he+){2,}h?)\\b|\\b(?:Ja*(?:ja+)+j?)\\b|\\b(?:Je*(?:je+)+j?)\\b|\\bJa+\\b|\\b(?:Ji*(?:ji+)+j?)\\b|\\b(?:Ha*(?:ha+)+h?)\\b|\\b(?:Jo*(?:jo+)+j?)\\b|\\b(?:o*(?:jo+)+j?)\\b|\\b(?:a*((?:ja+)|(?:js+))+j?)\\b|\\b(?:A*((?:JA+)|(?:JS+))+J?)\\b";
final String string = "jajajajajaja\n"
+ "jejejejeje\n"
+ "jijijijijij\n"
+ "ji\n"
+ "ja\n"
+ "je\n"
+ "hahahahahahaaaaa\n"
+ "Hahahaaa\n"
+ "Hahaaahaaha\n"
+ "hahaahaaaah\n"
+ "haaaaahaaahahahaaaaah\n"
+ "heheeheheeeeheeeheh\n"
+ "jajajaj\n"
+ "jaja\n"
+ "ja\n"
+ "jejejej\n"
+ "jeje\n"
+ "je\n"
+ "jijijiji\n"
+ "jiji\n"
+ "ji\n"
+ "ajajajaja\n"
+ "ahahahaha\n"
+ "ejejejeje\n"
+ "aaajajaja\n"
+ "jajaaajajaaajaaaa\n"
+ "JAJAJAJAJAJAJAJ\n"
+ "HAHAHAHAAAAHAHAHAHAAA\n"
+ "Hahahahahaha\n"
+ "JAJAJAJA\n"
+ "AAJAJAJA\n"
+ "JAJAAAJAJAJAAAAJ\n"
+ "he \n"
+ "hehe\n"
+ "haha\n"
+ "ha \n"
+ "has \n"
+ "hamaca \n"
+ "Jajajajaja\n"
+ "Jaja\n"
+ "Jejejejejeje\n"
+ "Jaa\n"
+ "Jijijijiiiiji\n"
+ "jiiijijijiiijijijiii \n"
+ "Jojojojojoj\n"
+ "jojojoj \n"
+ "Hahaa \n"
+ "Jejeee\n"
+ "jajaaaa\n"
+ "Jajaaaa\n"
+ "jajaj\n"
+ "jajajajsjaja\n"
+ "jajajssjsjsjajsja\n"
+ "jsjsjsjsjsjsj\n"
+ "JAJAJSJAJSSJAJSJSJAJSSSSJ \n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html