看板 Python 關於我們 聯絡資訊
真是太感謝你了^^ 還想再請問一個問題.. ※ 引述《rclrn (Aethanyc)》之銘言: : 官方文件寫: : findall(pattern, string) : Return a list of all non-overlapping matches in the string. : 所以要找重疊的patter,只能自己寫了,例: : import re : s='Lawrence and Peter are my best friend' : m=[] : for i in range(len(s)): : x = re.match('\w{2}', s[i:]) : if hasattr(x, 'group'): ^^^^^^^^^^^^^^^^^^ 這行我不懂為什麼要這樣寫.. : m.append(x.group()) : print m 對不起啊>"<我知道我的問題很笨 但是我盡力了.. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.25.192
rclrn:沒match到字串,x會是None,所以要確定x有group這個method, 06/01 23:33
rclrn:才可以用x.group() 06/01 23:35
alltoher:恩恩 我了解了^^ 謝謝!! 06/02 11:11