/(\d\.?){1,4}/ # $1 is last octet matched /((\d\.?){1,4})/ # $1 is IP address, $2 is last octet matched