lua-users home
lua-l archive

Re: Equivalent to scanf()?

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


> Lpeg to read a bunch of numbers seems like serious overkill. Perhaps I
> still don't *get* Lpeg, perhaps I don't think grammar-driven
> programming is a good clear way to do most things.
One of the main points of Lpeg is that you can use grammars, but you
don't have to. For instance, to simply match a list of integers
separated by spaces you can use the following code:
 require 're'
 line = "-123 453 2100"
 print(re.match(line, "( [ \t]* {[+-]? [0-9]+} )*"))
 --> -123 453 2100
(The curly brackets build a capture; parentheses only group things.)
-- Roberto

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