Extract matter between matching parenthesis.

Discussion in 'Perl Misc' started by Pradeep, Jul 9, 2005.

  1. Pradeep

    Pradeep Guest

    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
     
    Pradeep, Jul 9, 2005
    #1
    1. Advertising

  2. Pradeep

    Guest

    Re: Extract matter between matching parenthesis.

    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.
     
    , Jul 9, 2005
    #2
    1. Advertising

  3. "Pradeep" <> wrote in news:1120893831.458780.259340
    @z14g2000cwz.googlegroups.com:

    > 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

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Jul 9, 2005
    #3
  4. Re: Extract matter between matching parenthesis.

    "" <> wrote in
    news::

    > well you didnt use parenthesis " ( ) "


    Please quote an appropriate amount of context when you post replies.

    Sinan


    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Jul 9, 2005
    #4
  5. Pradeep

    Pradeep Guest

    Re: Extract matter between matching parenthesis.

    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. Sinan Unur wrote:
    > "Pradeep" <> wrote in news:1120893831.458780.259340
    > @z14g2000cwz.googlegroups.com:
    >
    > > 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
    >
    > --
    > A. Sinan Unur <>
    > (reverse each component and remove .invalid for email address)
    >
    > comp.lang.perl.misc guidelines on the WWW:
    > http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    Pradeep, Jul 9, 2005
    #5
  6. Pradeep

    Anno Siegel Guest

    Re: Extract matter between matching parenthesis.

    Pradeep <> wrote in comp.lang.perl.misc:
    > A. Sinan Unur wrote:
    > > "Pradeep" <> wrote in news:1120893831.458780.259340
    > > @z14g2000cwz.googlegroups.com:


    Top-posting moved in context. Please read the posting guidelines, as
    you have been asked to.

    > > > 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.
    > >

    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Jul 9, 2005
    #6
    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. Rogue Noir
    Replies:
    6
    Views:
    2,475
    Arquebus257WeaMag
    Aug 2, 2003
  2. Amit Khemka
    Replies:
    8
    Views:
    314
    Amit Khemka
    Nov 23, 2005
  3. Frank Guerino
    Replies:
    8
    Views:
    215
    Adam Prescott
    Oct 2, 2010
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    251
    Marc Bissonnette
    Jan 13, 2004
  5. NamSa

    want extract to parenthesis

    NamSa, May 1, 2009, in forum: Perl Misc
    Replies:
    3
    Views:
    112
Loading...

Share This Page