Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2015-07-01 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (9 votes), past polls