re.sub problem
- From: "veracon" <veracon@xxxxxxxxx>
- Date: 31 Mar 2006 05:33:32 -0800
I'm trying to make a (tiny) template system (Cheetah and like have far
more than what I need), but I've run into a problem. To simplify
everything, I've decided to make for loops matching the indentation
level of the open and close statements; it appears to work fine, but
apparently it chokes once there are empty lines inside the string being
replaced in.
It's a bit hard to explain, so I'll just show an example:
stm = re.compile('\n(\s+)\{\{for (.+?) in
(.+?)\}\}\n?(.+?)\n\\1\{\{end for\}\}', re.M)
data = re.sub(stm, self.handle_for, data)
I do have a self.handle_for, and I can see that it's not called if I
give it the following string:
[... (not beginning of actual string) ]
{{for baz in bar}}
<p>foo:{baz}</p>
b
{{end for}}
There, nothing is matched; if there wasn't an empty line, it would
match something.
What am I doing wrong?
.
- Follow-Ups:
- Re: re.sub problem
- From: RunLevelZero
- Re: re.sub problem
- From: veracon
- Re: re.sub problem
- Prev by Date: Re: any() and all() on empty list?
- Next by Date: Re: re.sub problem
- Previous by thread: Re: Working with files in a SimpleXMLRPCServver
- Next by thread: Re: re.sub problem
- Index(es):
Relevant Pages
|