fork download
package main  
 
import (
    "regexp"
    "fmt"
)
 
func main() {
    s := "runcmd -name abcd xyz -descr abc def"
	re1 := regexp.MustCompile(`^(.*? -name\b).*?(-descr\b.*)?$`)
	result := re1.FindStringSubmatch(s)
	fmt.Printf(result[1] + "..." + result[2])
	
	fmt.Printf("\n")
	
	s2 := "runcmd -name abcd xyz"
	result2 := re1.FindStringSubmatch(s2)
	fmt.Printf(result2[1] + "..." + result2[2])
}
Success #stdin #stdout 0s 3284KB
stdin
Standard input is empty
stdout
runcmd -name...-descr abc def
runcmd -name...