[Tutor] Re: lists in re?

Andrei project5 at redrival.net
Sat Sep 6 20:12:24 EDT 2003

Andreas Zwinkau wrote:
> Ave


> I'm currently working on something wiki-like and i use regular
> expressions very much to format the content. The bad part is, it gets
> worse, so i'd thought about making it more elegant. Is there any way to
> make replacements with re and use lists or a dictionary?

If you mean you want to make a list of re's and apply them all inside a 
loop (or something like that): sure, why not? You can put anything you 
like in lists or dictionaries.

I've taken your Italic and Underline regexes:

 >>> relist = [re.compile("''(.+?)''"), re.compile("__(.+?)__")]
 >>> results = [ r.match("__underscore__ blabla") for r in relist ]
 >>> print results
[None, <_sre.SRE_Match object at 0x01681D20>]

Apparently the first regex (the one for the italics) doesn't match, but 
the second one does.


Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V 
ernq gur yvfg, fb gurer'f ab arrq gb PP.

More information about the Tutor mailing list