Matching block of nested brace pairs

Discussion in 'Perl Misc' started by Peng Yu, Jun 13, 2010.

  1. Peng Yu

    Peng Yu Guest

    Suppose I have some C++ code like the following, I want to match the
    whole namespace x block.

    namespace x
    {
    namespace y
    {
    ....
    }

    }

    The following webpage shows brace-matching for perl regex. But I don't
    find the matchpairs module. (I'm using perl 5.10.1). Would you please
    let me know if there is a way to match block of nested braces in perl?

    http://dev.perl.org/perl6/rfc/145.html
     
    Peng Yu, Jun 13, 2010
    #1
    1. Advertising

  2. >>>>> "PY" == Peng Yu <> writes:

    PY> Would you please let me know if there is a way to match block of
    PY> nested braces in perl?

    Yes, there is. What did you find when you consulted the FAQ?

    Charlton


    --
    Charlton Wilbur
     
    Charlton Wilbur, Jun 14, 2010
    #2
    1. Advertising

  3. Peng Yu

    Peng Yu Guest

    On Jun 13, 7:07 pm, Charlton Wilbur <> wrote:
    > >>>>> "PY" == Peng Yu <> writes:

    >
    >     PY> Would you please let me know if there is a way to match blockof
    >     PY> nested braces in perl?
    >
    > Yes, there is.  What did you find when you consulted the FAQ?


    http://faq.perl.org/perlfaq6.html#Can_I_use_Perl_regul

    The example on this link is daunting to me. I have read perlre.

    $re = qr{ ( # paren group 1
    (full function)
    foo
    ( # paren group 2
    (parens)
    \(
    ( # paren group 3
    (contents of parens)
    (?:
    (?> [^()]+ ) # Non-parens without
    backtracking
    |
    (?2) # Recurse to start
    of paren group 2
    )*
    )
    \)
    )
    )
    }x;

    I still don't understand it how it works. What doesn't "Recurse to
    start of paren group 2"?

    For my specific problem (C++ namespace), would you please show me how
    to do it and explain it to me how it works? Thank you!
     
    Peng Yu, Jun 14, 2010
    #3
  4. >>>>> "PY" == Peng Yu <> writes:

    PY> The example on this link is daunting to me. I have read perlre.

    PY> I still don't understand it how it works. What doesn't "Recurse
    PY> to start of paren group 2"?

    Do you understand what "recurse" means? Do you understand what "paren
    group 2" means?

    PY> For my specific problem (C++ namespace), would you please show
    PY> me how to do it and explain it to me how it works? Thank you!

    Frankly, no, because if I do, you'll ignore the explanation and ask
    comp.lang.perl.misc the next time you have a problem to solve, and I'm
    already tired of seeing you ask FAQs. You really have two options: you
    can put in the work to understand what you're doing, or you can hire
    someone, for money, who will write code to your specification.

    Charlton


    --
    Charlton Wilbur
     
    Charlton Wilbur, Jun 14, 2010
    #4
  5. Peng Yu <> wrote:
    >The following webpage shows brace-matching for perl regex. But I don't
    >find the matchpairs module. (I'm using perl 5.10.1). Would you please
    >let me know if there is a way to match block of nested braces in perl?


    You keep asking very basic questions and questions that are answered in
    the FAQ. I _VERY_STRONGLY_ suggest you familiarize yourself with the
    FAQ.

    Here is the last fish for you: "perldoc -q nest":
    "How do I find matching/nesting anything?"

    jue
     
    Jürgen Exner, Jun 14, 2010
    #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. morrell
    Replies:
    1
    Views:
    1,000
    roy axenov
    Oct 10, 2006
  2. Evan

    remove matching pairs

    Evan, Dec 14, 2006, in forum: Python
    Replies:
    2
    Views:
    266
  3. Alvin
    Replies:
    8
    Views:
    1,033
  4. Orson

    Matching brace in eclipse

    Orson, Jun 23, 2008, in forum: Java
    Replies:
    8
    Views:
    1,999
    Patricia Shanahan
    Jul 4, 2008
  5. Jason Sweat
    Replies:
    17
    Views:
    561
    Nikolai Weibull
    Nov 6, 2004
Loading...

Share This Page