Matching block of nested brace pairs

P

Peng Yu

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
 
C

Charlton Wilbur

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
 
P

Peng Yu

    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!
 
C

Charlton Wilbur

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
 
J

Jürgen Exner

Peng Yu said:
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
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top