import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?<syslog_pri>(^\\<\\d*\\>))|(^(?<facility>[^\\.]*)\\.(?<severity>[^\\s]*)))?\\s*(?:%\\{SYSLOGTIMESTAMP:timestamp\\}|%\\{TIMESTAMP_ISO8601:timestamp\\}) %\\{SYSLOGHOST:iporhost\\}(?<messgae>.*)";
final String string = "<165>\n"
+ "User.Notice 2016-01-02 00:00:33 1.1.66.15 1.1.66.15 02/01/2016 00:00:00 NTP: Synchronization OK.\n"
+ "Local7.Warning 2016-01-02 00:00:43 1.1.5.6 319129: 14w1d: %CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on GigabitEthernet1/0/21 (780), with name_a FastEthernet3 (1).\n";
final String subst = "";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
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