(.*) instead of (.*?)

Posted by EBAGHAKI on Stack Overflow See other posts from Stack Overflow or by EBAGHAKI
Published on 2010-04-07T11:16:59Z Indexed on 2010/04/07 11:23 UTC
Read the original article Hit count: 165

Filed under:
|

Suppose we have this html content, and we are willing to get Content1, Content2,.. with regular expression.

<li>Content1</li>
<li>Content2</li>
<li>Content3</li>
<li>Content4</li>

If I use the line below

preg_match_all('/<li>(.*)<\/li>/', $text, $result);

i will get an array with a single row containing:

Content1</li>
<li>Content2</li>
<li>Content3</li>
<li>Content4

And by using this code:

preg_match_all('/<li>(.*?)<\/li>/', $text, $result);

i will get an array with 4 row containing Content1, Content2, ...

Why (.*) is not working since it means match any character zero or more times

© Stack Overflow or respective owner

Related posts about regex

Related posts about php