Python: re..find longest sequence

后端 未结 5 639
清歌不尽
清歌不尽 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 08:07

    Using re:

     m = re.search(r"(\bdiNCO diamine\b\s?)+", polymer_str)
     len(m.group(0)) / len("bdiNCO diamine")
    

提交回复
热议问题