You missed a couple of things and that may be the culprit.
if ($regex(ip,$3-,/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g) > 0) {
This will match any IP addresses:
on *:TEXT:*:#: {
if ($regex($1-,/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g)) echo -a $regml(1)
}