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

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>

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".

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