Extract matter between matching parenthesis.

P

Pradeep

Hi,

I was wrting a perl program and just got struck with one problem. The
file is having the following text in a line.
{My own text is {Prad{e}ep}}

Now from this text i have to take out text between the Second
parenthesis i.e. Prad{e}ep only.

This kind of text appears repeatdly in the file.

I don't how can i do that. If you can, please write a few lines of code
for me.

Cheers,
Pradeep
 
E

echohtp

well you didnt use parenthesis " ( ) " but if you want to use the curly
braces this should do the trick,

while ( <> ) {
if (/\{(.*) \{(.*}+)\}(.*)\}/){
do something with $_;
}
im not really sure if that will work 100% i think something is wrong
because of the two sets of {} that are within each other, but i hope
this puts you on the right track.
 
A

A. Sinan Unur

I was wrting a perl program and just got struck with one problem. The
file is having the following text in a line.
{My own text is {Prad{e}ep}}

Now from this text i have to take out text between the Second
parenthesis i.e. Prad{e}ep only.

You asked a FAQ:

perldoc -q balanced

Please also read the posting guidelines for this group.

Sinan
 
P

Pradeep

I have already gone through a function extract_bracketed but couldn't
get how to use it. Can you please tell me how can i use it to get the
text between the matching brace.
Please give me some line of code as it makes me more clearer to
understand.
 
A

Anno Siegel

Top-posting moved in context. Please read the posting guidelines, as
you have been asked to.
I have already gone through a function extract_bracketed but couldn't
get how to use it. Can you please tell me how can i use it to get the
text between the matching brace.
Please give me some line of code as it makes me more clearer to
understand.

The documentation of Text::Balanced has a few code examples for
extract_bracketed(). Start with those. If you can't get it to do what
you expect, ask specific questions about your code.

Most of us here are reluctant to sit down and write code for someone
who hasn't shown any in the first place.

Anno
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top