space := regexp.MustCompile(`\s+`) str := space.ReplaceAllString("Hello \t \n world!", " ") fmt.Println(str) // "Hello world!"