Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

regex - "Unknown escape sequence" error in Go

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...