Saturday, 15 January 2011

php - My regular expression doesn't know when to stop -



php - My regular expression doesn't know when to stop -

i'm trying match (the name in particular):

<tr> <th class="name">name:</th> <td>john smith</td> </tr>

like this:

preg_match('/<th class="name">name:<\/th>.+?<td>(.+)<\/td>/s', $a, $b);

however, while matches name, doesn't stop @ end of name. keeps going 150 or characters. why this? want match name.

make lastly quantifier non-greedy: preg_match('/<th class="name">name:<\/th>.+?<td>(.+?)<\/td>/s', $a, $b);

php regex greedy regex-greedy

No comments:

Post a Comment