I\'m trying to extract whatever data inside ${}.
For example, the data extracted from this string should be abc.
git commit -m
You need to escape $, { and } in the regex.
re := regexp.MustCompile("\\$\\{(.*?)\\}")
match := re.FindStringSubmatch("git commit -m '${abc}'")
fmt.Println(match[1])
Golang Demo
In regex,
$ <-- End of string
{} <-- Contains the range. e.g. a{1,2}
You can also use
re := regexp.MustCompile(`\$\{([^}]*)\}`)