Regular expression for validating IP addresses

Let's say, we would like to determine if particular symbols are valid public IPv4 address.

# valid octet, 0-255
octet = '1?[0-9][0-9]?|2([0-4][0-9]|5[0-5])'

# 4 valid octets separated with dots
octet_with_dot = octet + '\.'

# IPv4-address
ip_regex = '^({a}){3}{b}$'.format(a=octet_with_dot, b=octet)

But does it belong to …

more ...