httpsgameweixinqqcomcgi-binh5staticappcenteract_specialhtmlclusterid=10000036u0026wechat_pkgid=appcenter_act_specialu0026ssid=3150u0026immersivePageBgIsDark=0u0026wechat_immersive=1u0026immersiveUISty
您可以使用字符串操作函数和正则表达式来截取字符串。
首先,您可以使用strings.Index函数找到"html"的索引位置。然后,使用字符串切片操作获取该索引之后的子字符串。最后,使用正则表达式来匹配第一个"\u0026"之前的内容。
下面是一个示例代码:
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
url := "https://game.weixin.qq.com/cgi-bin/h5/static/appcenter/act_special.html?clusterid=10000036\u0026wechat_pkgid=appcenter_act_special\u0026ssid=3150\u0026immersivePageBgIsDark=0\u0026wechat_immersive=1\u0026immersiveUIStyle=1\u0026pre_inject_data=%5Bobject+Object%5D\u0026preInjectData=%5Bobject+Object%5D\u0026abt=64\u0026rpt_allpath=16304_999999_3150_999999_3150_8812_2881_8812_3154_2890_3150\u0026from_wechat_pkgid=pureprofile_index"
// 查找"html"的索引位置
index := strings.Index(url, "html")
if index == -1 {
fmt.Println("未找到\"html\"")
return
}
// 获取"html"之后的子字符串
subStr := url[index+len("html"):]
// 使用正则表达式匹配第一个"\u0026"之前的内容
re := regexp.MustCompile(`^(.*?)\\u0026`)
match := re.FindStringSubmatch(subStr)
if len(match) > 1 {
fmt.Println(match[1])
} else {
fmt.Println("未找到匹配的内容")
}
}
输出结果为:
?clusterid=10000036
请注意,由于正则表达式中的反斜杠是特殊字符,所以需要使用两个反斜杠来转义
原文地址: https://www.cveoy.top/t/topic/h1u1 著作权归作者所有。请勿转载和采集!