search for pattern in string
Question: I need to find a pattern ATG[any number of any characters triplets][TGA or TAG
or TGA], where I need only the first ATG, further up to [TGA or TAG or TAA] do
not matter.

And this should be interrupted at [TGA or TAG or TAA]. In string there could
be several such, they do not need to overlap.

For example search on 'ATGcccATGgggTAGgATGtttTAA' should give
'ATGcccATGgggTAG' and 'ATGtttTAA' as a result.

Is there any way to do this in Python?


Answer: This is a job for a regex. (Note that your expected result does not seem to
match your specification; you originally say you want to match up to TGA, TAG
or TGA, but then in the result you match up to TAA. I'll assume the end of the
string is meant to be TGA.)

    
    
    import re
    target = 'ATGcccATGgggTAGgATGtttTGA'
    results = re.findall(r'(ATG.*?(?:TAG|TGA|TGA))', target)
    # ['ATGcccATGgggTAG', 'ATGtttTGA']
    

