[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.1.4] "attempt to index global 'data' (a nil value)
- From: Peter Cawley <lua@...>
- Date: Sun, 24 Jul 2011 21:23:56 +0100
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">