import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "SPECGRID([\\s\\S]*?)\\/";
final String string = "MAPAXES -- Generated : Petrel\n"
+ " 159589.61 7782837.94 159589.61 7783837.94 160589.61 7783837.94 /\n\n"
+ "GRIDUNIT -- Generated : Petrel\n"
+ " METRES /\n\n"
+ "SPECGRID -- Generated : Petrel\n"
+ " 3 26 120 1 F /\n\n"
+ "COORDSYS -- Generated : Petrel\n"
+ " 1 120 /\n";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (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