regex matching rst code block?

E

Edward K. Ream

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 :)



Edward
 
S

Sybren Stuvel

Edward K. Ream enlightened us with:
Here is a little regular expression puzzle. I wish a regex that
matches an rst code block, that is,

I'll assume you mean reStructuredText with 'rst'.

Why not convert the reStructuredText to XML and parse that?

Sybren
 
P

Peter Otten

Edward said:
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
 
E

Edward K. Ream

Why not convert the reStructuredText to XML and parse that?

Because the problem arises for the jEdit syntax colorer whose most powerful
pattern matcher is a regex.

Edward
 
E

Edward K. Ream

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

Thanks for this. I'll try it out.

Edward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top