I have a string that is randomly generated:
polymer_str = \"diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine\"
I\'d
import re pat = re.compile("[^|]+") p = "diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine".replace("diNCO diamine","|").replace(" ","") print max(map(len,pat.split(p)))