LPeg: inserting previous captures by substitution
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: LPeg: inserting previous captures by substitution
- From: Александр Машин <alex.mashin@...>
- Date: 2015年7月25日 01:45:19 +0700
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