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\b).*?(-descr\b.*)?$`)
  11. result := re1.FindStringSubmatch(s)
  12. fmt.Printf(result[1] + "..." + result[2])
  13.  
  14. fmt.Printf("\n")
  15.  
  16. s2 := "runcmd -name abcd xyz"
  17. result2 := re1.FindStringSubmatch(s2)
  18. fmt.Printf(result2[1] + "..." + result2[2])
  19. }
Success #stdin #stdout 0s 3284KB
stdin
Standard input is empty
stdout
runcmd -name...-descr abc def
runcmd -name...