I have the below response from some telnet server
String response = "I:BARCO@noiclt22815||K:CMS||O:REgetPerspectiveList||A0:googleP||A1:yahooP||A2:gmail||A3:test||A4:hello||A16:CCTV Barco||A17:CCTV: Corridor CC||A18:CCTV: DR Andy Warhol||A19:CCTV: DR Gaudi (Analog)||A20:CCTV: DR Miro||A21:CCTV: Entrance CC||A22:CCTV: Gaudi Demo Room Megapixel||";
I want to get the attributes value for e.g A0, A1 etc and therefore I write the below logic
String[] strings = response.split("[||]");
List<String> list = new ArrayList<>();
for (String string : strings) {
if (string.contains(":")) {
String[] attributes = string.split(":");
if (attributes[0].startsWith("A")) {
list.add(attributes[1]);
}
}
}
But my problem is that string.split(":") split gives me string array but I requires only two length size string array only. For e.g. response A17 attribute gives me "CCTV" as attributes[1] and "Corridor CC" as attributes[2] but I requires "CCTV: Corridor CC" as attribute [1] only.
What regular expression I should write in string.split(regexp) so that string can be split based on first instance of colon operator only with exactly two length size string array.