dongzi0850 2017-05-29 19:08
浏览 26
已采纳

非贪婪的正则表达式吃太多[重复]

This question already has an answer here:

i have a string

<div class="line"><input name="sid" value="" type="hidden"><img src="1.jpg" height="40" width="180"><input name="word" size="30" maxlength="50" value="" type="text"></div>

and i trying to find and replace whole input with name = word, with this regexp:

/<input .+?word.+?>/ui

preg_match returns this:

array (
  0 => '<input name="sid" value="" type="hidden"><img src="1.jpg" alt="CAPTCHA" height="40" width="180"><input name="word" size="30" maxlength="50" value="" type="text">',
)

please help me to write working regexp

</div>
  • 写回答

2条回答 默认 最新

  • drkug66408 2017-05-29 19:11
    关注

    Use this one: /<input[^>]+name="word".+?>/ui

    In your pattern it finds first <input and then until word... If you use <input[^>]+ it will find <input and than group of simbols except closing > until name="word".

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口