[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Problem with table key iteration when string keys are unpredictable
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 22 May 2013 20:08:29 +0200
2013/5/22 marbux <firstname.lastname@example.org>:
> My thanks to you all. I will test each of these methods and go with
> the one that seems the most foolproof, given other code in the script.
> A special thanks for noticing that the script also needs to escape
> magic characters, which I had not yet caught.
Since nobody has up to now supported Sean's suggestion of LPEG,
I'll do so now. I recently put in the required amount of activation energy
to get my LPEG competence going, and the reaction is now exothermic.
In non-chemical terms, there's a steep learning curve but once you
reach the plateau you just keep going effortlessly.
Building a pattern that tries several possibilities in a prescribed order
is one of the most basic LPEG constructs: a1+a2+a3+...+an
Prescribing the replacement is hardly less basic:
Saying "move up one character if there is no match" is easy too
Do the substitutions and leave the rest unchanged:
Cs, P = lpeg.Cs, lpeg.P
pat = Cs((P"ABC"/"abc" + P"AB"/"de" + P"A"/"f"+P(1)/".")^0)