fork download
  1. package main
  2.  
  3. import (
  4. "regexp"
  5. "fmt"
  6. )
  7.  
  8. func main() {
  9. s := "runcmd -name abcd xyz -descr abc def"
  10. re1 := regexp.MustCompile(`^.*? -name`)
  11. result := re1.FindStringSubmatch(s)
  12. fmt.Printf(result[0])
  13.  
  14. s2 := "runcmd -name abcd xyz"
  15. result2 := re1.FindStringSubmatch(s2)
  16. fmt.Printf(result2[0])
  17. }
Success #stdin #stdout 0s 3284KB
stdin
Standard input is empty
stdout
runcmd -nameruncmd -name