import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<bar>\\+[+\\-=]+\\+)(?P<headline>.*?)(\\+[+\\-=]+\\+)(?P<body>.*?)(\\+[+\\-=]+\\+)";
final String string = "+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
+ "| No | ID | Name | VNFM | VIM | Tenant | VNF Package | Flavor | Level | Aspect | VNF Status | Job Status | Scale Opt | Scale Mode | Scale Unit | Workflow | Created At | Visible |\n"
+ "+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
+ "| 0 | 0960ad53-bf7a-4c56-b980-cfa05a33fe71 | vzw_u13_cp3 | NSA_VNFM | simvim | vran | vzw_u13_cp3_i12i00 | VRAN-FLAVOR | 0 | SA_CPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:35:51 | true |\n"
+ "| 1 | 33434187-2d82-48bd-9fd0-c67f2a8c9c87 | vzw_usm14 | NSA_VNFM | simvim | vsm | vzw21a_usm14 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 14:22:03 | true |\n"
+ "| 2 | 94b68ddb-06e6-45ae-a7dc-bf9204f61aa3 | vzw_usm12 | NSA_VNFM | simvim | vsm | vzw21a_usm12 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:15:55 | true |\n"
+ "| 3 | b60fdfff-c8d7-4656-bd77-d4621c1efbe5 | vzw_usm13 | NSA_VNFM | simvim | vsm | vzw21a_usm13 | VEMS-FLAVOR-TINY | 0 | AS_CF=0,AS_PS=0 | vnf.instance.instantiate.end | COMPLETED | Disabled | Manual Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2020-12-24 13:51:24 | true |\n"
+ "| 4 | c3de1762-57fb-4c0f-875e-e3b960629663 | vzw_u13_up3 | NSA_VNFM | simvim | vran | vzw_u13_up3_i12i00 | VRAN-FLAVOR | 0 | SA_UPC=0 | vnf.instance.instantiate.end | COMPLETED | Enabled | Auto Scale | VDU | workflow_etsi-com-vnf_nfvo_direct_1_0_0.jar | 2021-01-12 04:26:30 | true |\n"
+ "+----+--------------------------------------+-------------+----------+--------+--------+--------------------+------------------+-------+-----------------+------------------------------+------------+-----------+--------------+------------+---------------------------------------------+---------------------+---------+\n"
+ "item count : 5\n"
+ "[vnf-list] OK";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
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