lua-users home
lua-l archive

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


Reuben Thomas wrote:
> > Why the spaces after the numbers and around the non-number letters are
> > matched?
> 
> Not the spaces, but the "nothings". All the elements of your pattern are
> optional.

Oops, thanks! I am a beginner both at Lua and RE, and I didn't knew I could
match "nothings"...
With pattern = "(-?%d+)", it works much better.

And to answer my second question, as the manual states: "gsub also returns,
as a second value, the total number of substitutions made.", and 'print'
takes and displays the two returned values. Using 'write' removes this unwanted
number...

The challenge is still open: in the "(-?%d*.?%d*[eE]?-?%d*)" pattern, all
elements are optionals, so I match 'nothings', and illegal numbers like '.' or
'.e1'.
I guess alternations (if that's what it is called) can be useful here. I
know there is a regex library somewhere, but I wanted to do it in 'pure',
standard Lua.

Regards.

-- 
--._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`--

Sent through GMX FreeMail - http://www.gmx.net