import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(.*?) : (.+? MB\\/s)( \\[.*)?$";
final String string = "Sequential Read : 135.091 MB/s\n"
+ "Sequential Write : 126.046 MB/s\n"
+ "Random Read 512KB : 44.569 MB/s\n"
+ "Random Write 512KB : 117.965 MB/s\n"
+ "Random Read 4KB (QD=1) : 0.468 MB/s [ 114.4 IOPS]\n"
+ "Random Write 4KB (QD=1) : 8.412 MB/s [ 2053.6 IOPS]\n"
+ "Random Read 4KB (QD=32) : 0.654 MB/s [ 159.6 IOPS]\n"
+ "Random Write 4KB (QD=32) : 10.751 MB/s [ 2624.7 IOPS]\n"
+ "Test : 1000 MB [C: 7.3% (64.9/889.4 GB)] (x5)\n"
+ "Date : 2015/12/09 22:06:02\n"
+ "OS : Windows 8.1 [6.3 Build 9600] (x64)";
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