Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
found = re.findall("g+", "fggfggggfggfg", re.DOTALL)
findall を使用してパターンの最長一致を見つけたいと思います。いくつかの解決策を見つけましたが、re.matchまたはのみですre.finditer。誰かアドバイスをください。
re.match
re.finditer
re.DOTALLこの場合は何もしないので、簡単にするために取り出しました。
re.DOTALL
>>> import re >>> max(re.findall("g+", "fggfggggfggfg"), key=len) 'gggg'
長さの順にすべてが必要な場合:
>>> sorted(re.findall("g+", "fggfggggfggfg"), key=len, reverse=True) ['gggg', 'gg', 'gg', 'g']