I want to extract last two field values from a variable of varying length. For example, consider the three values below:
fe80::e590:1001:7d11:1c7e
ff02::1:ff1f:fb6
fe80::7cbe:e61:f5ab:e62 ff02::1:ff1f:fb6
These three lines are of variable lengths. I want to extract only the last two field values if i split each line by delimiter :
That is, from the three lines, i want:
7d11, 1c7e
ff1f, fb6
ff1f, fb6
Can this be done using split()? I am not getting any ideas.
If
sis the string containing the IPv6 address, useto get the last two components. The
split()method will return a list of all components, and the[-2:]will slice this list to return only the last two elements.