import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^TEXT\\h([A-Z0-9]{14})";
final String string = "Material B7E671143D244B\n"
+ "====================================\n"
+ "TEXT 2F3139D816C34D 1\n"
+ "TEXT B6A968EF2505A2 1\n"
+ "TEXT 35206697A04F91 1\n"
+ "TEXT EB485AF490D83D 1\n"
+ "TEXT 0DAB42294BD9B3 1\n"
+ "TEXT 3D6525BEE360E1 0\n\n"
+ "Material D6906B886B06E3\n"
+ "====================================\n"
+ "TEXT 0CCECCCCFB62AE 1\n"
+ "TEXT 1E14CB29AB43F0 1\n"
+ "TEXT FB7F0DCE9B5950 1\n\n"
+ "Material 431831490FD5C9\n"
+ "====================================\n"
+ "TEXT 9D77B6474696D8 1\n"
+ "TEXT D04DEE5DF130A4 1\n"
+ "TEXT B6A968EF2505A2 1\n"
+ "TEXT 8C37245A4F0F81 1\n"
+ "TEXT A39FAFFC5ABC06 1\n"
+ "TEXT D24199644F2EE6 1";
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