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条)

报告相同问题?

悬赏问题

  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题