On Wed, Apr 16, 2008 at 12:20 AM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:
> Sharan Basappa wrote:
>
> > Gary Stainburn wrote:
> >
> > >
> > > On Monday 14 April 2008 16:35, Sharan Basappa wrote:
> > >
> > >
> > > > I am trying to capture the text between two tokens. These tokens
> > > > always exist in pairs but can occur N times.
> > > > I somehow dont get what I want.
> > > >
> > > > $str =~ m/tokena(.*)tokenb/ms;
> > > > print $1;
> > > >
> > >
> > > Try
> > >
> > > $str =~ m/tokena(.*?)tokenb/ms;
> > >
> >
> >
> > actually I tried this before posting this question. The issue is that
> > regex stops after first match.
> >
>
>  Show us a short but _complete_ program, and we can help you correct it.
>
>
>  --
>  Gunnar Hjalmarsson
>  Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
>  --
>
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>  http://learn.perl.org/

I have gone through the text-balanced doc and tried few examples
myself. Looks like I need
some help on this module usage and capabilities.
Basically the text I am trying to extract is embedded inside two
tokens (say {}),
but it can occur anywhere in the input text stream. I tried using extract_tagged
function, but that seems to succeed only if the text starts with the tag I am
specifying.
For example, the following example returns expected value (i.e. {abc}):
#!/usr/bin/perl
#use warnings;
use lib
"/u/basappas/local/perl/perm_install/lib/perl5/site_perl";
use Text::Balanced qw (
                        extract_delimited
                        extract_bracketed
                        extract_quotelike
                        extract_codeblock
                        extract_variable
                        extract_tagged
                        extract_multiple

                        gen_delimited_pat
                        gen_extract_tagged
                       );

$text = q{{abc}12345};
($extracted, $remainder) = extract_tagged($text, '{', '}');
print "$extracted \n";

The following example does not (difference is that $text does not
start with {):#!/usr/bin/perl
#use warnings;
use lib
"/u/basappas/local/perl/perm_install/lib/perl5/site_perl";
use Text::Balanced qw (
                        extract_delimited
                        extract_bracketed
                        extract_quotelike
                        extract_codeblock
                        extract_variable
                        extract_tagged
                        extract_multiple

                        gen_delimited_pat
                        gen_extract_tagged
                       );

$text = q{12{abc}12345};
($extracted, $remainder) = extract_tagged($text, '{', '}');
print "$extracted \n";

The other question I have is that I would like to use text-balanced
module to extract multiple
occurences of these strings that are tagged by these tokens. Is that possible?

Regards

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to