lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Jul 24, 2011 at 9:20 PM, Gilles Ganault <gilles.ganault@free.fr> wrote:
> Currently, this code returns all the characters between the first and
> last occurence of the pattern, instead of just the pattern:
>
> for line in data:lines() do
>        -- for w in string.gmatch(line, '<a href="/places/.-\.php">') do
>        for w in string.gmatch(line, '<a href="/places/.-%.php">') do
>                print(w)
>        end
> end
>
> I read that using the "-" quantifier makes "string" non-greedy, so I
> guess I must be doing something wrong.

Works for me:
line=[[<a href="/places/1.php">1</a> <a href="/places/2.php">2</a>]]
for w in string.gmatch(line, '<a href="/places/.-%.php">') do print(w) end

Gives:
<a href="/places/1.php">
<a href="/places/2.php">