import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(b|y)([0-9])+\\/";
final String string = "? 143/200\n"
+ "a2/-1.6ppm 145/200\n"
+ "? 80/200\n"
+ "? 148/200\n"
+ "Int/AG/-1.2ppm,Int/GA/-1.2ppm 86/200\n"
+ "y16/-1.1ppm 180/200\n"
+ "y16+i/-1.0ppm 133/200\n"
+ "y17/-1.3ppm 170/200\n"
+ "y17+i/-1.8ppm 125/200\n"
+ "y18/-2.3ppm 116/200";
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