import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "All files[^|]*\\|[^|]*\\s+([\\d\\.]+)";
final String string = "---------------------|----------|----------|----------|----------|----------------|\n"
+ "File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |\n"
+ "---------------------|----------|----------|----------|----------|----------------|\n"
+ "[32;1mAll files [0m |[32;1m 85.61[0m |[33;1m 59.85[0m |[32;1m 84.06[0m |[32;1m 87.14[0m |[31;1m [0m |\n"
+ "[32;1m cli [0m |[32;1m 95.37[0m |[33;1m 70.21[0m |[33;1m 76.47[0m |[32;1m 97.12[0m |[31;1m [0m |\n"
+ "[32;1m add.js [0m |[32;1m 100[0m |[32;1m 83.33[0m |[32;1m 100[0m |[32;1m 100[0m |[33;1m 12[0m |\n\n"
+ "---------------------|----------|----------|----------|----------|----------------|\n"
+ "File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |\n"
+ "---------------------|----------|----------|----------|----------|----------------|\n"
+ "All files | 85.61 | 59.85 | 84.06 | 87.14 | |\n"
+ " cli | 95.37 | 70.21 | 76.47 | 97.12 | |\n"
+ " add.js | 100 | 83.33 | 100 | 100 | 12 |\n"
+ " adduser.js | 100 | 83.33 | 100 | 100 | 21,23 |\n"
+ " new.js | 100 | 75 | 100 | 100 | 18,20 |";
final Pattern pattern = Pattern.compile(regex);
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