in reply to Help!!! How to find duplicates?

Traditionally, RE can't do this kind of balanced matching. Modern perl 5.10s have special support for it and even older perls have special (?{ code }) matchers than can do the counting for you. What you really want is a parser.

Your best bet is probably: Text::Balanced rather than RE. Although, to be honest, I've done it both ways and prefer using (?{ code }) to T::B as I find it difficult to operate.

-Paul

Replies are listed 'Best First'.
Re^2: Help!!! How to find duplicates?
by stylerr (Initiate) on Dec 07, 2009 at 16:27 UTC

    Thanks for your comments.

    Here is solution.

    use Regexp::Common qw /balanced/; my $ttt = '$sub24835->($sub24839->( $sub24828->($sub24840->("( a1"),$sub24841->(" a1 ) ")), $sub24830->($sub24853->("( a2 "),$sub24854->(" a2 )")),$sub24828->($su +b24840->("( a1"),$sub24841->(" a1 ) ")),$sub24842->($sub24843->("0"), +$sub24830->($sub24853->("( a2 "),$sub24854->(" a2 )")),$sub24828->($s +ub24840->("( a1"),$sub24841->(" a1 ) "))),$sub24830->($sub24853->("( +a2 "),$sub24854->(" a2 )")),$sub24828->($sub24840->("( a1"),$sub24841 +->(" a1 ) ")),$sub24832->($sub24855->("1"),$sub24856->($sub24857->("| + a3"),$sub24859->("a3 |")),$sub24858->("a3")),$sub24849->($sub24850-> +("1"),$sub24830->($sub24853->("( a2 "),$sub24854->(" a2 )")),$sub2483 +2->($sub24855->("1"),$sub24856->($sub24857->("| a3"),$sub24859->("a3 +|")),$sub24858->("a3")))))'; my @ttt = $ttt =~ /(\$sub\d+->$RE{balanced}{-parens=>'()'}).*?\1/sg; print scalar @ttt, "\n"; print join("\n", @ttt);