import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?=(?!(.)\\1)([^\\DO:105-93+30])(?-1)(?<!\\d(?<=4))).[^\\WHY?]$";
final String string = "┌──────────────────────────────┐\n"
+ "│ What is the Meaning of Life? │\n"
+ "│ Potential Answers │\n"
+ "└──────────────────────────────┘\n\n"
+ "Dear regex, please pick one of the following lines.\n\n"
+ "---\n\n"
+ "The meaning of life, according to the Oxford English Dictionary, is the condition or attribute of living or being alive.\n"
+ "Why should life have a meaning? What a stupid question.\n"
+ "42\n"
+ "Meaning of life has to be qualified. The meaning of your life to you is not the same as the meaning of your life to a dictator. And what about the meaning of a bee's life, or of a bacteria's life. In other words, see the two previous answers, which can be summarized by 'what a stupid question.'\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