I am trying to find all occurrences of A's with a maximum 2 non A characers (either G, C or T) in a string and i am particularly interested by the longest occurence. Howeved when i try this on .. lets say.. the following

The regex won't work because your first match takes you all the way up to the third G, so the next match will be all the A's. I would think to get it to work you'd need to go back to the last non-A after each match by resetting pos().

Found ATAAAAAAGAAAAAA at pos 2 Found AAAAAAGAAAAAAGAAAAAAAAAAAAAAA at pos 4 Found AAAAAAGAAAAAAAAAAAAAAA at pos 11 Found AAAAAAAAAAAAAAA at pos 18 Found A at pos 37 Found AAAAAAAAGAGA at pos 40 Found AGA at pos 49 Found A at pos 51 Found ATAAGA at pos 55 Found AAGA at pos 57 Found A at pos 60 Found AAATAAA at pos 63 Found AAA at pos 67

....thats not perfect as it misses out ACCAAAAAAAA, but its the best I can do for now :)