我得到None作爲此代碼的答案。當我單獨做電子郵件或電話時,代碼就可以工作。但使用兩者都返回無。請幫忙!Python REGEX搜索返回無作爲答案
進口重新
string = 'Love, Kenneth, [email protected], 555-555-5555, @kennethlove Chalkley, Andrew, [email protected], 555-555-5556, @chalkers McFarland, Dave, [email protected], 555-555-5557, @davemcfarland Kesten, Joy, [email protected], 555-555-5558, @joykesten'
contacts = re.search(r'''
^(?P<email>[-\w\d.+][email protected][-\w\d.]+) # Email
(?P<phone>\d{3}-\d{3}-\d{4})$ # Phone
''', string, re.X|re.M)
print(contacts.groupdict)
1.刪除'$',''^ 2.添加',\ S * '#電子郵件前'# –
感謝使用這個工作! –