dongxian0421 2015-07-21 03:34
浏览 37
已采纳

正则表达式匹配模式,除非它与特定字符串结束

I'm having a little trouble coming up with a regex for my particular situation. This is what I have.

"#<call:(\d+)>(?:(?!\/MM).)+?(\s+)?(?=\<)#ims"

I need to match the following example.

<call:5>anything <

But I don't want to match this...

<call:5>anything/mm <

That's working ok, but the problem is that it won't match this...

<call:5>anything/mmm <

I need the regex to match anything provided anything does not end with /mm. I know it's going to be something small I'm overlooking, but could you point out what I'm doing wrong please?

  • 写回答

2条回答 默认 最新

  • doumindang2416 2015-07-21 07:00
    关注

    If one can assume that the call tag contents to be matched will not contain

    • spaces after an (allowed?) /mm string or
    • < characters (except at the end),

    the following seems to work:

    <call:(\d+)>(?:(?!\/mm[\s<]).)+?(\s+)?(?=\<)
    

    EDIT:

    I think the corner cases can be solved as well, try this instead:

    <call:(\d+)>(?:(?!\/mm\s*?<).)+?(\s+)?(?=\<)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器