CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
need to capture part of string!



Jan 8, 2010, 10:47 AM

Post #1 of 3 (6592 views)
need to capture part of string! Can't Post

I have a string with lower and upper case letters. I need to capture upper case letters, for example, and possibly find where it starts and end in the string. Here is a sample data:


I have a bunch of these strings as lines of a file and I am interested in upper case characters A,C,G,T.

I tried:

while (<>){
$x =~/([ACGT]+)/;
I know the capured string should be in $1.

I need some help/guide


Jan 8, 2010, 12:24 PM

Post #2 of 3 (6587 views)
Re: [gudhead] need to capture part of string! [In reply to] Can't Post

while (<>){ 
if (/([ACGT]+)/) { print "$1\n" }

See also:


Jan 9, 2010, 4:56 AM

Post #3 of 3 (6560 views)
Re: [gudhead] need to capture part of string! [In reply to] Can't Post

You can also capture more than one at a time with an array:


use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

my $seq = "aaaaaaggggGGGGTTttttttttttttggccgAAAAAATTTTTTTTCCCGGagggt";

my @captured = $seq =~ /([ACGT]+)/g;
print Dumper \@captured;


I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives