Find the longest prefix of a string not in a set of characters