fork download
  1. package main
  2. import (
  3. "fmt"
  4. "regexp"
  5. )
  6.  
  7. func delete_empty (s []string) []string {
  8. var r []string
  9. for _, str := range s {
  10. if str != "" {
  11. r = append(r, str)
  12. }
  13. }
  14. return r
  15. }
  16.  
  17. func main(){
  18. text := "red 1 green 3 blue"
  19. result := regexp.MustCompile("red|green|blue").Split(text, -1)
  20. fmt.Printf("%q\n",result)
  21. fmt.Printf("%q\n",delete_empty(result))
  22. }
Success #stdin #stdout 0s 4572KB
stdin
Standard input is empty
stdout
["" " 1 " " 3 " ""]
[" 1 " " 3 "]