lua-users home
lua-l archive

Re: Regex question

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


On Thu, Aug 18, 2005 at 10:32:49AM -0500, Keith Pimmel wrote:
> _,_,last = string.find(str,'([^\n]*)')
Lua's patterns aren't regular expressions and don't handle the
complexity of a regexp. Perhaps you want:
 local last
 for s in string.gfind(str, '([^\n]+)') do
 last = s
 end
The for loop will iterate over all substrings that match the pattern,
returning the last one. I changed the '*' in the pattern to a '+' to
avoid matching "\n" and returning and empty string.
Cheers!
-- 
Shannon Stewman | Let us walk through the waning night,
Caught in a whirlpool, | As dawn-rays tickle our toes, the dew soothes
A quartering act: | Our blistered soles, and damp bones stir
Solitude or society? | As crimson cracks under the blue-grey sky.

AltStyle によって変換されたページ (->オリジナル) /