Jason Wang
Jason Wang

Reputation: 1

LPeg how to match an odd integer?

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

Upvotes: 0

Views: 25

Answers (1)

Brynne Taylor
Brynne Taylor

Reputation: 116

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]

Upvotes: 0

Related Questions