medium - accepted / - tried
An IPv4 Address is represented in dot-decimal notation, consisting of 4 numbers( called 'octet'), each ranging from 0 to 255, like
220.127.116.11. It has 32 bit, so there are maximum 2^32 = 4,294,967,296 IPv4 addresses.
Leading zeroes are not allowed in IPv4, like
01.01.01.01 is invalid.
An IPv6 Address have 128 bits (which is a lot), separated by 8 groups (called 'hexadectet', or 'hextet', not fixed yet).
Each group has 16 bits, so could be represented by a hexadecimal string at 4 digits, such as
leading zeroes are allowed in IPv6.
There are other valid format of IPv6 addresses, like Zero compression, but it is beyond the scope here, you can ignore them.
You are given some random string, please write a function if it is valid IPv4 or IPv6 address.
Can you solve it with regular expressions ?
Let's try to solve this problem within 15 minutes.