Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- EMAIL_CHARS = string.ascii_letters + string.digits + '.'
- def find_name_start(text, at_index):
- first_index = 0
- for index in range(at_index-1, -1, -1):
- if text[index] == at_index:
- break
- if text[index] not in EMAIL_CHARS:
- first_index = index + 1
- break
- return first_index
- def find_name_end(text, at_index):
- first_index = 0
- for index in range(at_index+1,len(text)):
- #if text[index] == at_index:
- # break
- if text[index] not in EMAIL_CHARS:
- first_index = index + 1
- break
- if index == len(text)-1:
- first_index = index + 1
- break
- # if text[index] == 0:
- return first_index
- def find_email(text):
- at_index = text.find('@')
- email_list = []
- while at_index > -1 :
- name_start = find_name_start(text, at_index)
- name_end = find_name_end(text, at_index)
- email = text[name_start : name_end]
- email_list.append(email)
- if name_start == at_index:
- email_list.remove(email)
- #if email_list == []:
- # print "Please, type in an email address"
- # return
- if name_end - 2 == at_index and name_end == 0:
- email_list.remove(email)
- # if name_end == 0:
- #email_list.remove(email)
- at_index = text.find('@',at_index+1)
- return email_list
- #print find_email("@gmail.com olle@gmail.com")
- #print find_email("olle@gmail.com @gmail.com")
- #print find_email("olle@ olle@gmail.com")
- #print find_email("olle@gmail.com olle@")
- #print find_email("@olle olle@gmail.com @olle")
- #print find_email("@gmail.com olle@gmail.com @gmail.com")
- #print find_email("")
- #print find_email("hej ehj olle@gmail.com @sfeeahfaf 1234 {[]9)8?#&")
- print find_email("@ olle@gmail.com")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement