正则表达式
package mainimport ("fmt""regexp""strings")var pattern = `^([\*]+)\n`var negate = falsevar content = `******************************************************************【记录时间】:2021-05-13 10:06:16【记录机器】:JY-weishangchen【请求IP】:10.6.151.100【请求地址】:https://w-wines-olapp.cofco.com/KmAPI/Api/Open/VipInfo/IsExistVip【请求身份】:FSJLB001【请求接口】:VipInfo/IsExistVip【请求商户】:55333【请求时间】:2021-05-13 10:06:16 099【请求Key】:xcx_mzh_shop_xxx【请求头】:{"CustId":55333,"Sign":"610d29ce1e510ef242dd9cd73478001f","Timestamp":1622167577,"Appid":"FSJLB001","Nonce":"xcx_mzh_shop_xxx","Version":"1.0"}【请求参数】:{"CustID":"55333","UnionId":"o9odR5hVeSzbRCjjC6aeLwMNpqFk"}【响应时间】:2021-05-13 10:06:16 130【响应内容】:{"data":false,"extInfo":null,"code":"0002","msg":"当前会员未注册","errmsg":"","IsOk":false}【执行耗时】:31******************************************************************`func main() {regex, err := regexp.Compile(pattern)if err != nil {fmt.Println("Failed to compile pattern:", err)return}matches := regex.MatchString(content)if negate {matches = !matches}fmt.Printf("%v\t%v\n", matches, content)lines := strings.Split(content, "\n")fmt.Printf("matches\t line\n")for _, line := range lines {matches := regex.MatchString(line)if negate {matches = !matches}fmt.Printf("%v\t%v\n", matches, line)}}
参考链接
https://play.golang.org/ https://www.elastic.co/guide/en/beats/filebeat/7.13/multiline-examples.html
