http://www.perlmonks.org?node_id=989272


in reply to extract only uppercases from string

I'm not sure it's easy to do it in just one regex.

But you can just use two steps:

my $seq = "G_I1E2_GTGGAG^303CTGgacgCCCTGC_I2E3_TACA"; $seq =~ s/[^ACTGactg]//g; my @result = $seq =~ /[ACTG]+/g; say for @result;

You can do it in one line if your version of perl is recent enough to support the r regex modifier:

perl -wE 'say for "G_I1E2_GTGGAG^303CTGgacgCCCTGC_I2E3_TACA" =~ s/[^AC +TGactg]//gr =~ /[ACTG]+/g;'

Replies are listed 'Best First'.
Re^2: extract only uppercases from string
by losher (Initiate) on Aug 23, 2012 at 10:53 UTC
    Little modification of your idea works for me!
    Thanks a lot!