package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?i)(?:http(s)?://)?([a-z][-\w]+(?:\.\w+)+(?:\S+)?)`)
var str = `Here is a sentence with a url containing a query string: https://www.google.com/search?q=mickmackusa&oq=mickmackusa&aqs=chrome..69i57j69i60.271j0j7&sourceid=chrome&ie=UTF-8 all good.
http://google.com
http://google.com.au
https://google.com.au
www.google.com
google.com
I went to the local food store and bought some food.\n\nI was able to find everything
I went to the local food store and bought some food.
I was able to find everything`
var substitution = "<a href="http$1://$2" target="_blank" title="$0">$0</a>"
fmt.Println(re.ReplaceAllString(str, substitution))
}
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/