Duncan Booth wote:
> If you must insist on using backslash escapes (which introduces the
> question of how you get backslashes into the output: do they have to be
> escaped as well?) then use string.Template with a custom pattern.
If anybody wants this, I worked out the following regular expressi
Duncan Booth wote:
> Also, of course, vars just needs to be something which quacks like a dict:
> it can do whatever it needs to do such as looking up a database or querying
> a server to generate the value only when it needs it, or even evaluating
> the name as an expression; in the OP's case it
Josiah Carlson <[EMAIL PROTECTED]> wrote:
> Samuel wrote:
>> On Sun, 17 Jun 2007 11:00:58 +, Duncan Booth wrote:
>>
>>> The elegant and lazy way would be to change your specification so
>>> that $ characters are escaped by $$ not by backslashes. Then you can
>>> write:
>>>
>> from string
Samuel wote:
> Thanks, however, turns out my specification of the problem was
> incomplete: In addition, the variable names are not known at compilation
> time.
> I just did it that way, this looks fairly easy already:
>
> ---
> import re
>
> def variable_sub_cb(match):
>
Samuel wrote:
> On Sun, 17 Jun 2007 11:00:58 +, Duncan Booth wrote:
>
>> The elegant and lazy way would be to change your specification so that $
>> characters are escaped by $$ not by backslashes. Then you can write:
>>
> from string import Template
> ...
>
> Thanks, however, turns o
On Sun, 17 Jun 2007 11:00:58 +, Duncan Booth wrote:
> The elegant and lazy way would be to change your specification so that $
> characters are escaped by $$ not by backslashes. Then you can write:
>
from string import Template
...
Thanks, however, turns out my specification of the
Samuel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> How would you implement a simple parser for the following string:
>
> ---
> In this string $variable1 is substituted, while \$variable2 is not.
> ---
>
> I know how to write a parser, but I am looking for an elegant (and lazy)
> way. Any idea?
>
The