I have the following function written in Go. The idea is the function has a string passed to it and returns the first IPv4 IP address found. If no IP address is found, an empty string is returned.
func parseIp(checkIpBody string) string {
reg, err := regexp.Compile("[0-9]+.[0-9]+.[0-9]+.[0-9]+")
if err == nil {
return ""
}
return reg.FindString(checkIpBody)
}
The compile-time error I'm getting is
unknown escape sequence: .
How can I tell Go that the '.'
is the actual character I'm looking for? I thought escaping it would do the trick, but apparently I'm wrong.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…