package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$`)
var str = `22.231.113.64
22.231.113.164
222.231.113.64
22.231.113.64
22.231.113.164
255.231.111.64
253.231.111.64
22.21.113.61
22.21.113.162
255.21.111.63
253.21.111.69
22.211.113.64
22.212.113.164
255.213.111.64
253.214.111.64
22.211.113.364
22.212.113.3164
255.213.111.464
253.214.111.564
not an ip address
not an ipv4 Address
Not an IPv5 Address`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/