import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[^\\n\\d{6,}](?:(?:[a-z\\s.]+(\\n[a-z\\s.])*)|.+)";
final String string = "xxx\n\n"
+ "27223525\n\n"
+ "West Food Group B.V.\n\n"
+ "52608670\n\n"
+ "Westcon\n\n"
+ "Group European Operations Netherlands Branch\n\n"
+ "30221053\n\n"
+ "Westland Infra Netbeheer B.V.\n\n"
+ "27176688\n\n"
+ "Wetransfer B.V.\n\n"
+ "34380998\n\n"
+ "WETRAVEL B.V.\n\n"
+ "70669783";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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