How to extract domain from URL with regular expression in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func main() {
	s := `https://www.collectivesolver.com/search?q=go`

	re := regexp.MustCompile(`^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)`)

	matches := re.FindAllString(s,-1)
	for _, element := range matches {
		fmt.Println(element)
	}
}
   
   
   
/*
run:
   
https://www.collectivesolver.com
 
*/

 



answered Aug 10, 2020 by avibootz

Related questions

...