import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=K{10}\\n)\\K.++(?!\\n-)";
final String string = "-----------------------\n"
+ "4046904\n\n\n"
+ "KKKKKKKKKKK\n"
+ "Laura Meyer\n"
+ "MassMutual Life Insurance\n"
+ "153 Vadnais Street\n\n"
+ "Chicopee, MA 01020\n"
+ "US\n"
+ "413-744-5452\n"
+ "lmeyer@massmutual.co...\n\n\n"
+ "KKKKKKKKKKK\n"
+ "373074210772222 02/12 6213 NA\n"
+ "-----------------------\n"
+ "4046907\n\n\n"
+ "KKKKKKKKKKK\n"
+ "Venkat Talladivedula\n\n"
+ "6105 West 68th Street\n\n"
+ "Tulsa, OK 74131\n"
+ "US\n"
+ "9184472611\n"
+ "venkat.talladivedula...\n\n\n"
+ "KKKKKKKKKKK\n"
+ "373022121440000 06/11 9344 NA\n"
+ "-----------------------";
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