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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



gudhead
Novice

Jan 8, 2010, 10:47 AM

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

hi,
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:

"aaaaaaggggggggttttttttttttttggccgAAAAAATTTTTTTTCCCGGagggt"

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


toolic
User

Jan 8, 2010, 12:24 PM

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


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


http://perldoc.perl.org/perlretut.html

See also: http://www.bioperl.org/wiki/Main_Page


shawnhcorey
Enthusiast


Jan 9, 2010, 4:56 AM

Post #3 of 3 (2449 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:

Code
#!/usr/bin/perl 

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;


__END__

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

Perl documentation is available at perldoc.perl.org. 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