Need help in Python regular expression
Vlastimil Brom
vlastimil.brom at gmail.com
Fri Jun 12 04:36:30 EDT 2009
2009/6/12 meryl <silverburgh.meryl at gmail.com>:
> On Jun 11, 9:41 pm, "Mark Tolonen" <metolone+gm... at gmail.com> wrote:
>> "meryl" <silverburgh.me... at gmail.com> wrote in message
>>
>> > I have this regular expression
>...
> I try adding ".*" at the end , but it ends up just matching the second
> one.
If there can be more matches in a line, maybe the non-greedy
quantifier ".*?", and a lookahead assertion can help.
You can try something like:
(?m)Render(?:Block|Table) (?:\(\w+\)|{\w+})(.+?(?=$|RenderBlock))?
(?m) multiline flag - also the end of line can be matched with $
.+? any character - one or more (no greedy, i.e. as little as possible)
(?=$|RenderBlock) the lookahead assertion - condition for the
following string - not part of the match - here the end of line/string
or "RenderBlock"
I guess, if you need to add more possibilities or conditions depending
on your source data, it might get too complex for a single regular
expression to match effectively.
hth
vbr
More information about the Python-list
mailing list