IP address validation added to link regex

link regex will now only match a valid ipv4 address

Also did some cleanup to the regex' replace callback and grouping.