如何解决未知转义序列的错误(以及另外2个错误)

I m trying to validate the image url using golang code but there is error in regular expression I'm showing my regular expression in this question:-

 var validation = regexp.MustCompile("(http(s?):)|([/|.|\w|\s])*\.(?:jpg|gif|png)")

Error:-

unknown escape sequence (and 2 more errors)

play link

\. is an invalid escape sequence. I would suggest you use backticks when defining regular expressions. e.g.

regexp.MustCompile(`^https?://.*\.(jpg|gif|png)$`) // this will just check if the url ends with jpg,gif,png

If you are not using the capture groups, this is a simpler approach. However when parsing or validating URLs, use url.Parse() which provides better validation.