in reply to Re: how to search for a pattern in a string within a certain range
in thread how to search for a pattern in a string within a certain range

My toughts, too. Regex's seem like an overly complicated solution to me; but, on the other hand, it's a good problem to learn some pretty empowering Regex strategies. So "Your mileage may vary."

Here is a quick sript that uses substr() and index() to find the search-for pattern and deletes everything up to the pattern plus that pattern. It also only searches up to the specified number of characters.

#!/usr/bin/perl use strict; use warnings; my @strings = ('ATGGCTAGTTTCAGT', 'GTTTATGGGTACGTGT', 'ATTGATACGGGTATTTAGGCTG', 'ATTAGGAAGTAGGACCCTAGG' ); my $search = 'TTT'; my $len = length($search); my @newStrings = map {my $indx = index(substr($_,0,8),$search); my $temp; if($indx == -1){ $temp = $_; }else{ $temp = substr($_, ($indx+$len),(length($_)-$in +dx-$len)); } } @strings; foreach my $indx1 (0..(scalar(@strings)-1)){ print "$strings[$indx1] ---> $newStrings[$indx1]\n"; } exit(0);

This script produces the following output:

ATGGCTAGTTTCAGT ---> ATGGCTAGTTTCAGT GTTTATGGGTACGTGT ---> ATGGGTACGTGT ATTGATACGGGTATTTAGGCTG ---> ATTGATACGGGTATTTAGGCTG ATTAGGAAGTAGGACCCTAGG ---> ATTAGGAAGTAGGACCCTAGG

If I understand the OP's inquiry, I think this does what is wanted.

The only thing I'm not clear on is what the OP expects to do if there are (1) multiple occurances, within the seek-or number of characters, of the search-for pattern in the string? and (2) what the result should be if there is a run of the search-for pattern (e.g., 'TTTTTTTTT' which has three intances of the search-for pattern in a run)?

ack Albuquerque, NM