import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "SPECGRID.*?\\n([ \\d]+)[\\s\\S]*?\\/";
final String string = "-- Generated [\n"
+ "-- Format : ECLIPSE keywords (grid geometry and properties) (ASCII)\n"
+ "-- Exported by : Petrel 2014.4 (64-bit) Schlumberger\n"
+ "-- User name : apitchford\n"
+ "-- Date : Friday, April 29 2016 15:20:42\n"
+ "-- Project : Glenloth19April2016.pet\n"
+ "-- Grid : Tartan Wide 3D grid 150 prop\n"
+ "-- Generated ]\n\n"
+ "PINCH -- Generated : Petrel\n"
+ " /\n\n"
+ "MAPUNITS -- Generated : Petrel\n"
+ " METRES /\n\n"
+ "MAPAXES -- Generated : Petrel\n"
+ " 156653.33 7788633.76 156653.33 7789633.76 157653.33 7789633.76 /\n\n"
+ "GRIDUNIT -- Generated : Petrel\n"
+ " METRES /\n\n"
+ "SPECGRID -- Generated : Petrel\n"
+ " 54 166 127 1 F /\n\n"
+ "COORDSYS -- Generated : Petrel\n"
+ " 1 127 /";
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