lua-users home
lua-l archive

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


On Sun, 24 Jul 2011 14:14:03 +0100, Peter Cawley <lua@corsix.org>
wrote:
>> for token in string.gmatch(line, '<a href="/places/.+?\.php">') do
>>        print(token)
>> end
>> ==========
>
>Lua's string library doesn't use any kind of regex. I would guess that
>the string library's .- is equivalent to the regex .+? construction,
>and that %. is equivalent to \. (the latter, expressed in a string,
>would also need an escaping slash).

Thanks for the tip. Apparently, Lua doesn't include a regex library,
and I can't figure out how to make its string library non-greedy.

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.

Thank you.