Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 ( [id://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

Replies are listed 'Best First'.
Re^2: how to remove characters before and after a search pattern in a string?
by jwkrahn (Abbot) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://826493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-16 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found