Python: re..find longest sequence

后端 未结 5 643
清歌不尽
清歌不尽 2021-01-06 07:28

I have a string that is randomly generated:

polymer_str = \"diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine\"

I\'d

5条回答
  •  悲哀的现实
    2021-01-06 07:59

    One was is to use findall:

    polymer_str = "diol diNCO diamine diNCO diamine diNCO diamine diNCO diol diNCO diamine"
    len(re.findall("diNCO diamine", polymer_str)) # returns 4.
    

提交回复
热议问题