import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".+left X:..(.+?)\\n.+Y:..(.+?)\\n.+\\n.+\\n.+:.(.+?)\\n.+:.(.+?)\\n";
final String string = "\n"
+ "xwininfo: Window id: 0x4800024 \"Yebe\"\n\n"
+ " Absolute upper-left X: 100\n"
+ " Absolute upper-left Y: 164\n"
+ " Relative upper-left X: 10\n"
+ " Relative upper-left Y: 45\n"
+ " Width: 1600\n"
+ " Height: 1200\n"
+ " Depth: 24\n"
+ " Visual: 0x6e\n"
+ " Visual Class: DirectColor\n"
+ " Border width: 0\n"
+ " Class: InputOutput\n"
+ " Colormap: 0x4800022 (not installed)\n"
+ " Bit Gravity State: ForgetGravity\n"
+ " Window Gravity State: NorthWestGravity\n"
+ " Backing Store State: NotUseful\n"
+ " Save Under State: no\n"
+ " Map State: IsViewable\n"
+ " Override Redirect State: no\n"
+ " Corners: +100+164 -860+164 -860-76 +100-76\n"
+ " -geometry 1600x1200+90-66";
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