Python: re..find longest sequence

后端 未结 5 644
清歌不尽
清歌不尽 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:57

    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)))
    

提交回复
热议问题