lua-users home
lua-l archive

LPeg: inserting previous captures by substitution

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


Dear All,
I wrote a simple LPeg grammar in re.lua syntax that matches a signless integer with digits grouped by spaces (there are several ways to do it in different cultures):
int <- digits spaces int / digits
digits <- [0-9]+
spaces <- %s+
It works, matching figures like "6 000 000".
I can also remove the spaces with substitution capture:
int <- {~ digits spaces -> '' int / digits ~}
digits <- [0-9]+
spaces <- %s+
It will match "6 000 000" and return "6000000".
But what if I want to return "6000000|6 000 000"? Can I memorise the original capture, before removing the spaces and insert it by substitution after processed string? I mean, can I do it with pure re syntax, without function captures?
Thanks in advance,
Alexander Mashin

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