duang8642 2019-02-05 16:28 采纳率: 0%
浏览 469

正则表达式查找字符串和反斜杠

I have these strings and they can come in a variety of ways such as:

id=PS\\ Old\\ Gen, value=34 and id=Code\\ Cache,value=22 etc.

I would like a regex that would extract anything after the = to the , so basically: PS\\ Old\\ Gen and Code\\ Cache etc.

I have written the following regex but can't seem to get the last word before the ,.

(([a-zA-z]+)\\{2})+

Any thoughts? This is for go language.

  • 写回答

3条回答 默认 最新

  • dotxxh0998 2019-02-05 16:31
    关注

    You can use this regex and capture your text from group1,

    id=([^,=]*),
    

    Explanation:

    • id= - Matches id= literally
    • ([^,=]*) - Matches any character except , or = zero or more times and captures in first grouping pattern
    • , - Matches a comma

    Demo

    Sample Go codes,

    var re = regexp.MustCompile(`id=([^,=]*),`)
    var str = `id=PS\\ Old\\ Gen, value=34 id=Code\\ Cache,value=22`
    
    res := re.FindAllStringSubmatch(str, -1)
    for i := range res {
        fmt.Printf("Match: %s
    ", res[i][1])
    }
    

    Prints,

    Match: PS\\ Old\\ Gen
    Match: Code\\ Cache
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂