[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Equivalent to scanf()?
- From: roberto@... (Roberto Ierusalimschy)
- Date: Wed, 14 Nov 2007 09:50:06 -0200
> 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