Golang: extract data with Regex

后端 未结 4 895
萌比男神i
萌比男神i 2021-02-12 16:00

I\'m trying to extract whatever data inside ${}.

For example, the data extracted from this string should be abc.

git commit -m          


        
4条回答
  •  有刺的猬
    2021-02-12 16:38

    Because $, { and } all have special meaning in a regex and need to be backslashed to match those literal characters, because * doesn't work that way, and because you didn't actually include a capturing group for the data you want to capture. Try:

    re := regexp.MustCompile(`\$\{.+?)\}`)
    

提交回复
热议问题