Cargo=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjMsImV4cCI6MTY4NTc2NDQwMSwiaWF0IjoxNjg1MTU5NjAxLCJpc3MiOiJDYXJnbyIsInN1YiI6InVzZXIgdG9rZW4ifQ.RU5I3BlZaxX7UK1T_8jfwBRZ3AHHzo1m7D9FbuA3Fg4; 7436229=skey=@Uyta2flI3;uin=o0007436229;p_skey=dEUcMe0G7WkFCVBcexDvR3XwPEFIrg9QASI18fixw_; 1023250836=skey=@HTv3Ryui3;uin=o1023250836;p_skey=5kIITiKrCb5rTCPHU2IWdwZUxCpSy54pzo2zKUJAU_ 这是一段cookie 请使用golang帮我取出单个的值
时间: 2023-10-15 11:03:56 浏览: 73
同样可以使用strings包和正则表达式来提取单个的值。以下是一个示例代码:
```go
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
str := "Cargo=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjMsImV4cCI6MTY4NTc2NDQwMSwiaWF0IjoxNjg1MTU5NjAxLCJpc3MiOiJDYXJnbyIsInN1YiI6InVzZXIgdG9rZW4ifQ.RU5I3BlZaxX7UK1T_8jfwBRZ3AHHzo1m7D9FbuA3Fg4; 7436229=skey=@Uyta2flI3;uin=o0007436229;p_skey=dEUcMe0G7WkFCVBcexDvR3XwPEFIrg9QASI18fixw_; 1023250836=skey=@HTv3Ryui3;uin=o1023250836;p_skey=5kIITiKrCb5rTCPHU2IWdwZUxCpSy54pzo2zKUJAU_"
re := regexp.MustCompile(`\b7436229=([^;]+)`)
match := re.FindStringSubmatch(str)
if len(match) > 1 {
value := strings.TrimSpace(match[1])
fmt.Println(value)
} else {
fmt.Println("Value not found")
}
}
```
输出:
```
skey=@Uyta2flI3
```
如果要提取其他键的值,只需要修改正则表达式中的数字即可。
阅读全文