import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=\\ id\\ \\|.)(([a-zA-Z0-9_]{8})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{4})-([a-zA-Z0-9_]{12}))";
final String string = "Created a new subnet: \n"
+ "+-------------------+------------------------------------------------+ \n"
+ "| Field | Value | \n"
+ "+-------------------+------------------------------------------------+ \n"
+ "| allocation_pools | {\"start\": \"10.42.42.2\", \"end\": \"10.42.42.254\"} | \n"
+ "| cidr | 10.42.42.0/24 | | dns_nameservers | | | enable_dhcp | True | \n"
+ "| gateway_ip | 10.42.42.1 | \n"
+ "| host_routes | | \n"
+ "| id | 3eded702-2909-4515-bf74-7c7c2c7c96e3 | \n"
+ "| ip_version | 4 | \n"
+ "| ipv6_address_mode | | \n"
+ "| ipv6_ra_mode | | \n"
+ "| name | Atelier | \n"
+ "| network_id | 5d15b14c-1d39-48d5-8f48-0dfd68c98d47 | \n"
+ "| tenant_id | d3c17d0e8bd742ed939794a98991886f \n"
+ "| +-------------------+------------------------------------------------+\n";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (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