package main import ( "fmt" "regexp" ) func main() { text := "A:99元,B:199元,积分:50" // 捕获【数字+元】整体,分组单独取出数字 re := regexp.MustCompile(`(\d+)元`) matches := re.FindAllStringSubmatch(text, -1) var amountList []string for _, item := range matches { // item[0] = 99元,item[1] = 99 纯数字 amountList = append(amountList, item[1]) } fmt.Println("仅提取金额数字:", amountList) }