import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(&|also|a|about|again|all|after|are(nt)?|arent|as|an(y)?|at|\n"
+ " bcuz|before|be(low)?|between|bring|but|by|and|can(not)?|close(d)?|could(nt)?|\n"
+ " cuz|do(nt)?|down|decide(d)?|decision|on(to)?|or|of|our|over|out|have(nt)?|he(re)?|\n"
+ " her|his|other(s)?|even|got(ten)?|for|from|get(s)?|got(ten)?|has(nt)?|havent|he(s)?|\n"
+ " him|his|if|in|to|in(to)?|is(nt)?||make|me|once|play(ed)?|role|say(s)?|seen|she(s)?|\n"
+ " should(nt)?|stop(ped)?|time|my|no(t)?|must(nt)?|now|you(re)?|your|want|want(ed)?|\n"
+ " watch(ed)?|way|we(re)?|will|with||i|a|is(nt)?|just|would(nt)?|before|that|the(re)?|\n"
+ " their|them|they|this|turn|when|at|how|it(s)?|which|who|after|then|if|how|because|know(s)?|\n"
+ " yet|[A-Za-z]{1,2}|http(s)?://.*|www\\..*)$";
final String string = "why should havent also a yet their";
final Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
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