Sandeep Deshpande wrote:
> Dear All,
> This is a sample code, I hope it would explain my problem.
> I want to extract some text from string based on some criteria.
> 1) My definition
> 2) Words
> 3) Non-Words
>
> My code goes as follows
>
> ===================================================================
> $ref=" <bold> This a test <\/bold><med >
> ";
>
> my $srch=qr(<bold>\ |<\/bold>|This\ a\ test)x;
>
> while ($ref =~ s/((?:$srch)|\w+|\W+)//s)
> {
> my ($word) = ($1);
> print "#=>: $word#\n";
> }
> ===================================================================
Try this one:
my $ref = " <bold> This a test <\/bold><med >\n";
my $srch = qr(<bold> |<\/bold>|This a test);
while ($ref =~ s/((?:$srch)|\w+|[^\s\w]+)//s) {
my $word = $1 || '<undef>';
print "'$word'\n";
}
__END__
> I get output like this, Since \W+ is more generic than $srch it captures \W+
> #=>: <#
> #=>: bold#
> #=>: > #
> #=>: This a test#
> #=>: </#
> #=>: bold#
> #=>: ><#
> #=>: med#
> #=>: >
> #
>
> But I want output in the following way.
>
> #=>: #
> #=>:<bold> #
> #=>: This a test#
> #=>: </bold>#
> #=>: <#
> #=>: med#
> #=>: >
> #
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs