在Go中使用regexp选择边框之间的文本

时间:2019-04-02 12:04:58

标签: regex go

代码示例:

proc := exec.Command(execString, arg01, arg02, arg03, arg04, arg05)
stdout, err := proc.Output()
res := string(stdout)
fmt.Printeln(res)

此代码的标准输出:

------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'cuba'
+--- Project ':cuba-client'
+--- Project ':cuba-client-tests'
+--- Project ':cuba-core'
..........

为此示例,我只需要选择项目名称,即beetwen ':'

cuba-client
cuba-client-tests
cuba-core
...........

我正在尝试:

re := regexp.MustCompile(`':(.*?)'`)
reg := re.FindAllString(res, -1)
fmt.Println(reg)

并输出:

':cuba-client'
':cuba-client-tests'
':cuba-core'
..............

我在做什么错了?

0 个答案:

没有答案