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

Rather than using a regular expression, you might want to consider using index to find the first occurance of your search pattern. If it is found within your initial range then you could follow Ratazong's advice and use substr to remove characters as required.

I hope this is helpful.

Cheers,

JohnGG

  • Comment on Re: how to search for a pattern in a string within a certain range

Replies are listed 'Best First'.
Re^2: how to search for a pattern in a string within a certain range
by ack (Deacon) on Mar 08, 2010 at 18:53 UTC

    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.

    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