使用golang正则获取匹配到的变量:
package main
import (
"regexp"
"log"
)
func main() {
var s1 string = "/admin/oss_apps/5f9500be682c4902b42ec7d16cf4b296/fa-bu-li-shi?%3Aoss_app_id=5f9500be682c4902b42ec7d16cf4b296&"
reg := regexp.MustCompile(/\w+/.+/(\w+)/.+
)
log.Println(reg.ReplaceAllString(s1, "$1"))
}
有疑问加站长微信联系(非本文作者)