Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: how to remove characters before and after a search pattern in a string?

by thunders (Priest)
on Mar 03, 2010 at 18:49 UTC ( #826493=note: print w/ replies, xml ) Need Help??


in reply to how to remove characters before and after a search pattern in a string?

since your pattern is a simple string, you can use index and substr.

my $str = "ACGTTGGCTATTGGGCCCGCT"; my $pattern = "GTT"; my $offset = index($str,$pattern) + length($pattern) + 3; $str = substr($str,$offset); print $str;


Comment on Re: how to remove characters before and after a search pattern in a string?
Download Code
Re^2: how to remove characters before and after a search pattern in a string?
by jwkrahn (Monsignor) on Mar 03, 2010 at 19:58 UTC

    Probably better as:

    my $str = "ACGTTGGCTATTGGGCCCGCT"; my $pattern = "GTT"; if ( ( my $offset = index $str, $pattern ) >= 0 ) { + substr $str, 0, $offset + length( $pattern ) + 3, ""; } print $str;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://826493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-08-23 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls