in reply to Re: Quantified Regex Replacement
in thread Quantified Regex Replacement

Thanks so much for your reply.
I am just wondering how can I just take away the two consecutive reversed brackets -- ][. Like this:
my $str = "TGC[CCC]CC[TTT]"; # Into my $rep = "TG[CCCCCTTT]";
Still my regex below doesn't do it right, it also removes two Cs in between:
$str =~ s/\]([ATCG]+)\[//;

Regards,
Edward

Replies are listed 'Best First'.
Re^3: Quantified Regex Replacement
by japhy (Canon) on Feb 23, 2006 at 14:48 UTC
    That's because your substitution matches the ]...[ part and replaces it with nothing! You'll have to replace it with $1, which in your regex, contains the letters in between the closing and opening brackets. s/\]([ACTG]+)\[/$1/

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart