dongqin1075 2013-10-18 03:15
浏览 53
已采纳

获得固定字符串匹配

I have the following fixed string.

edbe801bf92fe7b770f72df2d722df0a

I need to get the 2df2d part after the fourth 7 and before the last 7

I tried matching with

[a-z0-9]*7[a-z0-9]*77[a-z0-9]*7(.*)

But its getting the wrong part of the string

Thanks.

  • 写回答

1条回答 默认 最新

  • dongse3348 2013-10-18 03:17
    关注

    Actually your pattern will match if you add another 7 after your capturing group.

    .... (.*)7
    

    But for readability and to save you a headache, I would simplify this.

    (?:[^7]*7){4}([^7]*)
    

    I used a non-capturing group here ?: to group the expression for multiple matches, but not to save it as a matched/captured portion of the string.

    Regular expression explanation:

    (?:        group, but do not capture (4 times):
     [^7]*     any character except: '7' (0 or more times)
       7       match '7'
    ){4}       end of grouping
    (          group and capture to \1:
     [^7]*     any character except: '7' (0 or more times)
    )          end of \1
    

    See live demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码