import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<DeviceId>\\w*)\\s+,\\s+(?<Description>[\\w\\'\\-]*[\\,\\s]?[\\w\\s]+)\\s+,\\s+(?<Model>[\\w\\s\\-()]*)\\s+,\\s+(?<Protocol>[A-Z]+)\\s+,\\s+(?<DevicePool>[\\w\\-]*)";
final String string = "name (constant) descripton (constant) name (constant) name (constant) name \n"
+ "=============== ========== ================ ========== ================================= ========== ==== ========== ======= \n"
+ "CSFCOGRADY , O'Grady, Conor CSF , Cisco Unified Client Services Framework , SIP , DP-GBLON-AL-DESKTOP\n"
+ "CSFJIWU , Wu, Jiayi CSF , Cisco Unified Client Services Framework , SIP , DP-GBLON-FH-DESKTOP\n\n"
+ "SEPB8621F6D62BB , Auto 2032 , Cisco 8961 , SIP , Default \n"
+ "SEPDC4A3E576074 , Auto 2000 , Cisco IP Communicator , SCCP , Default \n"
+ "SEP00FFF74297DE , Auto 2047 , Cisco IP Communicator , SCCP , Default \n"
+ "SEP001A2B3C0000 , Sip Test Lines A , Third-party SIP Device (Advanced) , SIP , Default \n"
+ "SEP001A2B3C0001 , Sip Test Lines B , Third-party SIP Device (Advanced) , SIP , Default \n"
+ "SEP68ECC5620C0E , Auto 2001 , Cisco IP Communicator , SCCP , Default \n"
+ "SEP8C1645309770 , Auto 2002 , Cisco IP Communicator , SCCP , Default \n"
+ "SEP1C1D862E9E8A , Auto 2022 , Cisco 8961 , SIP , Default \n"
+ "SEP8C1645309837 , Auto 2003 , Cisco IP Communicator , SCCP , Default \n"
+ "SEP8C164530972E , Auto 2004 , Cisco IP Communicator , SCCP , Default\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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