dongzhi5386 2018-11-08 14:16
浏览 73
已采纳

使用preg_replace在正则表达式中使用特殊字符的问题

i have problem with regexp which is trying to find if phrase I search is within a <hx> tag or not

this is the example: https://regex101.com/r/xAlJJc/3

as you can see there's exactly 1 match in example, this is fine

the problem is that the moment you add a dot, comma or other character to this <h1>test string</h1> regexp is going crazy and show 2 matches

does anyone knows how to make sure that this: https://regex101.com/r/xAlJJc/4

will not find any matches for "test string"?

  • 写回答

2条回答 默认 最新

  • doujimiao7480 2018-11-09 14:36
    关注

    In my case the solution was to use this regex:

    (Test)(?![^>]*?[^<]*?<\/a>)(?![^>]*?[^<]*?<\/button>)(?![^>]*?[^<]*?<\/h[1-6]>)

    thank you for your efforts guys :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求指导储层饱和度及含水率测井解释
  • ¥200 建三维地震工区写入sgy到指定目录
  • ¥30 靶向捕获测序探针设计自学
  • ¥15 写代码写代码单片机代码写代码写数字按键代码
  • ¥15 django按照距离进行排序
  • ¥15 (标签-微信|关键词-微信公众号)
  • ¥15 matlab中mjs用不了
  • ¥15 Ios抖音直播的时候如何添加自定义图片在直播间!
  • ¥60 riscv-pulpino总线上挂载axi从机
  • ¥15 ssh登录页面的问题