LPeg how to match an odd integer?

55 Views Asked by At

R"09"^0 * S"13579" does not work because R"09"^0 will consume all digits and S"13579" will have nothing to match.

1

There are 1 best solutions below

0
On

Normally, odd <- [0-9] odd / [1357] is correct enough to match small numbers. Alternatively, you could first check it's not last digit of an odd number, before consuming it:

odd <- (!([1357] ![0-9]) [0-9])* [1357]