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

First GTT:
s/^.*?GTT.{3}//s
Last GTT:
s/^.*GTT.{3}//s
Every GTT:
s/^.*GTT.{3}//s

Replies are listed 'Best First'.
Re^2: how to remove characters before and after a search pattern in a string?
by jrsimmon (Hermit) on Mar 03, 2010 at 18:15 UTC

    I don't see the difference bewteen
    Last GTT:

    s/^.*GTT.{3}//s
    and
    Every GTT:
    s/^.*GTT.{3}//s
    . Shouldn't it have been
    s/^.*GTT.{3}$//s
    ?

    Also, won't the last one remove everything preceding the last occurrence of GTT (assuming it's followed by 3 somethings), and not just every occurrence of 'GTT' within the string?

      There isn't any difference. Deleting everything before every instance and deleting everything before the last instances gives the same result.

      No, adding $ makes it so it will only match if GTT is three characters from the end of the string (or 4 if the last character is \n).