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. 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. Ken Fine
    Replies:
    2
    Views:
    167
    Ken Fine
    Feb 24, 2004
  2. Musical Notation
    Replies:
    1
    Views:
    67
    Steven D'Aprano
    Aug 1, 2013
  3. Joel Goldstick
    Replies:
    0
    Views:
    75
    Joel Goldstick
    Jul 31, 2013
  4. Beth McNany
    Replies:
    0
    Views:
    83
    Beth McNany
    Jul 31, 2013
  5. Serhiy Storchaka
    Replies:
    0
    Views:
    81
    Serhiy Storchaka
    Jul 31, 2013
Loading...

Share This Page