import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?i)(?!-+\\s+Page\\s+\\d+-+|Python\\s+Regular\\s+Expression\\s+\\d{2}.+\\d{4}|.+Python\\s+Proprietary|PYTHON\\s+RE SPECIFICATION\\s+Version.+\\s+page\\s+\\d+|Python\\s+Regular\\s+Expression\\s+Specification).+$";
final String string = "\n"
+ "This module provides regular expression matching operations.\n"
+ " \n"
+ "Regular expressions use the backslash character ('\\') to indicate special forms\n"
+ "or to allow special characters to be used without invoking their special\n"
+ "meaning.\n"
+ " \n"
+ "Python Regular Expression 02 December 1999 \n"
+ " \n"
+ " Python Proprietary \n\n"
+ "----------------------- Page 292-----------------------\n\n"
+ "PYTHON RE SPECIFICATION Version 2.7 [Vol 9, Part Q] page 983 \n\n"
+ "Python Regular Expression Specification \n\n"
+ "It is important to note that most regular expression operations are available as\n"
+ "module-level functions and RegexObject methods. The functions are shortcuts that\n"
+ "don’t require you to compile a regex object first, but miss some fine-tuning\n"
+ "parameters.\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