regex matching rst code block?

Discussion in 'Python' started by Edward K. Ream, Sep 3, 2006.

  1. 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

    --------------------------------------------------------------------
    Edward K. Ream email:
    Leo: http://webpages.charter.net/edreamleo/front.html
    --------------------------------------------------------------------
     
    Edward K. Ream, Sep 3, 2006
    #1
    1. Advertising

  2. 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
    --
    The problem with the world is stupidity. Not saying there should be a
    capital punishment for stupidity, but why don't we just take the
    safety labels off of everything and let the problem solve itself?
    Frank Zappa
     
    Sybren Stuvel, Sep 3, 2006
    #2
    1. Advertising

  3. Edward K. Ream

    Peter Otten Guest

    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
     
    Peter Otten, Sep 3, 2006
    #3
  4. > 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
    --------------------------------------------------------------------
    Edward K. Ream email:
    Leo: http://webpages.charter.net/edreamleo/front.html
    --------------------------------------------------------------------
     
    Edward K. Ream, Sep 3, 2006
    #4
  5. > r":):\s*\n(\s*\n)*((\s+).*?\n)(((\4).*?\n)|(\s*\n))*)"

    Thanks for this. I'll try it out.

    Edward
    --------------------------------------------------------------------
    Edward K. Ream email:
    Leo: http://webpages.charter.net/edreamleo/front.html
    --------------------------------------------------------------------
     
    Edward K. Ream, Sep 3, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    581
    Ray Andraka
    Mar 3, 2005
  2. morrell
    Replies:
    1
    Views:
    1,006
    roy axenov
    Oct 10, 2006
  3. Alvin
    Replies:
    8
    Views:
    1,037
  4. Tim Golden

    Nudge needed for rst to html

    Tim Golden, Sep 6, 2007, in forum: Python
    Replies:
    0
    Views:
    271
    Tim Golden
    Sep 6, 2007
  5. Replies:
    2
    Views:
    282
    Terry Reedy
    Nov 18, 2008
Loading...

Share This Page