in reply to Find element in array
The secret-sauce that you need to read more about are the /g and /c modifiers of regular expressions. If you are looking for characters in a string which are not valid, and can devise a regex which identifies them, then these modifiers will let you loop through the same string multiple times finding all the matches. Yes, it turns your original approach to the problem precisely upside-down. There are lots of good examples elsewhere on the Internet, including some particular to DNA strings.