regex matching rst code block?

Peter Otten __peter__ at web.de
Sun Sep 3 12:09:55 EDT 2006


Edward K. Ream wrote:

> Here is a little regular expression puzzle.  I wish a regex that matches
> an rst code block, that is,

> '::' followed by a group of lines all indented by at least as much as the
> first non-blank line following the '::'
 
> My guess is that this is not possible.  Can anyone prove me wrong :-)

Try

r"(::\s*\n(\s*\n)*((\s+).*?\n)(((\4).*?\n)|(\s*\n))*)"

Probably buggy and too complicated, but you didn't post a good test suite...

Peter




More information about the Python-list mailing list