matching curly braces and regular expressions

Discussion in 'Perl' started by Dustin D., Aug 27, 2003.

  1. Dustin D.

    Dustin D. Guest

    Let's say I have a text file with the following:

    food {
    fruits {
    apples
    oranges
    pears
    }
    dairy {
    ice_cream {
    chocolate
    vanilla
    }
    milk
    }
    }

    I want to use a regular expression to crop out the "dairy" section.
    That is, I want to find the word dairy and count the curly braces, and
    using this, crop out a part of a file.

    Is there an easy way to do this with regular expressions? I wrote a
    function that counts letters and so forth, but it's not full-proof and
    has some problems.

    Thanks,
    Dustin
     
    Dustin D., Aug 27, 2003
    #1
    1. Advertisements

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. Geathaa
    Replies:
    1
    Views:
    646
    Martin Honnen
    Sep 12, 2003
  2. TJ
    Replies:
    5
    Views:
    736
  3. Replies:
    10
    Views:
    1,094
    John Machin
    May 17, 2009
  4. kindly
    Replies:
    11
    Views:
    516
    Rhodri James
    Jun 14, 2009
  5. Ion Freeman
    Replies:
    7
    Views:
    1,311
    Arne Vajhøj
    Jun 24, 2009
  6. Ken Fine
    Replies:
    2
    Views:
    276
    Ken Fine
    Feb 24, 2004
  7. Musical Notation
    Replies:
    1
    Views:
    146
    Steven D'Aprano
    Aug 1, 2013
  8. Rotwang
    Replies:
    1
    Views:
    138
    Chris Angelico
    Jul 31, 2013
Loading...