Hello monks,
I wanna balance the tag with paren (escape char). Below coding does not yield correct output for me. If i remove paren around 1989, then i'm getting the correct output.
Can anyone suggest me how to get the output without removing paren?
use Regexp::Common;
use Cwd;
use Regexp::Common::balanced;
my $x = q(<extract>
dfjklasjfdk jdflkasdjflkasd (1989)
fdjsaflkajdf kkjdslkfjasdk
<extract>
dfsdlkfjdsa fdfadsfsad</extract> sajflksadjfklasd
fkasdjfsadf Close</extract> <line>
df adfjlkadf</line><extract>
dfjalkdf akdjfklasdjflkadsjfasdclose1</extract>);
my $e;
my @ele = ('extract','line');
foreach $e (@ele)
{
while ($x=~/$RE{balanced}{-begin=>"<$e"}{-end=>"<\/$e>"}{-keep}/gs)
{
my $begin = "$1";
$x =~ s/($begin)/&$e($1,$e)/egsi;
print "$x\n";
}
}
sub extract
{
my $a = $_[0];
my $tag = $_[1];
$a =~ s/<\/$tag>/<\/$tagæ>/gi;
my @a=map(!/^(<e)/?("\n<e>".$_."<\/e>"):"\n".$_, split(/\n/,$a));
return "@a";
}
sub line
{
my $a = $_[0];
my $tag = $_[1];
$a =~ s/<\/$tag>/<\/1$tag>/gi;
my @a=map(!/^(<li)/?("\n<li>".$_."<\/li>"):"\n".$_, split(/\n/,$a));
return "@a";
}
Thanks in advance for your suggestion
regards,
--B
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.