I have a string that is randomly generated:
polymer_str = \"diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine\"
I\'d
One was is to use findall:
findall
polymer_str = "diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine" len(re.findall("diNCO diamine", polymer_str)) # returns 4.