I have aa:bb::cc:yy:zz
string that needs to be split so that I have an array with aa:bb::cc
, yy
, zz
. those. I want to create two substrings from the last with :
as a separator and the remaining as an element of the array. What is the best way to achieve this?
Example:
aa:bb::cc:yy:zz --> ['aa:bb::cc','yy','zz'] dd:ff:gg:dd:ee:ff:fg --> ['dd:ff:gg:dd:ee','ff','gg']
I save the IP address: port: protocol as a key in the file and split the ":" to get the IP, port, proto back, and everything works fine when the IP address is limited to IPv4. Now I want it to be ported to IPv6, in which case the IP address contains ":", so I canβt get the correct IP address by dividing it by ":".
source share