import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\[[a-z-]*\\]\\s[\\w\\d\\s\\-\\=\\\"\\.\\:\\@]+";
final String string = "[access-control]\n"
+ "realm-id = \"name2\"\n"
+ "description = \"Register_to_Bryansk_RTU\"\n"
+ "source-address = \"0.0.0.0\"\n"
+ "destination-address = \"0.0.0.0:5060\"\n"
+ "application-protocol = \"SIP\"\n"
+ "transport-protocol = \"ALL\"\n"
+ "[access-control]\n"
+ "access = \"permit\"\n"
+ "average-rate-limit = \"0\"\n"
+ "trust-level = \"high\"\n"
+ "minimum-reserved-bandwidth = \"0\"\n"
+ "invalid-signal-threshold = \"0\"\n"
+ "maximum-signal-threshold = \"0\"\n"
+ "[access-control]\n"
+ "untrusted-signal-threshold = \"0\"\n"
+ "nat-trust-threshold = \"0\"\n"
+ "max-endpoints-per-nat = \"0\"\n"
+ "nat-invalid-message-threshold = \"0\"\n"
+ "deny-period = \"30\"\n"
+ "cac-failure-threshold = \"0\"\n"
+ "untrust-cac-failure-threshold = \"0\"\n"
+ "[access-control]\n"
+ "last-modified-by = \"admin@0.0.0.0\"\n"
+ "last-modified-date = \"2015-01-22 09:01:19\"\n"
+ "[access-control]\n"
+ "realm-id = \"name\"\n"
+ "description = \"\"\n"
+ "source-address = \"0.0.0.0\"\n"
+ "destination-address = \"0.0.0.0:5060\"\n"
+ "application-protocol = \"SIP\"\n"
+ "transport-protocol = \"ALL\"\n"
+ "access = \"permit\"\n"
+ "average-rate-limit = \"0\"\n"
+ "trust-level = \"high\"\n"
+ "minimum-reserved-bandwidth = \"0\"\n"
+ "invalid-signal-threshold = \"0\"\n"
+ "maximum-signal-threshold = \"0\"\n"
+ "untrusted-signal-threshold = \"0\"\n"
+ "nat-trust-threshold = \"0\"\n"
+ "max-endpoints-per-nat = \"0\"\n"
+ "nat-invalid-message-threshold = \"0\"\n"
+ "deny-period = \"30\"\n"
+ "cac-failure-threshold = \"0\"\n"
+ "untrust-cac-failure-threshold = \"0\"\n"
+ "last-modified-by = \"admin@0.0.0.0\"\n"
+ "last-modified-date = \"2014-10-23 11:26:39\"";
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