Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def extract_sender(value):
- value=re.sub('[^@\s.A-Za-z0-9_\-]', '', str(value)) #1. filter out any characters that arent '@',[space],a numerical or alpha numerical character
- emailpos=value.find('@') #2. get the index position of where @ is situated in the filtered value
- spacebeforeemail=value.rfind(' ',0,emailpos) #3. get the index of the space before the email
- fe=value[spacebeforeemail:] #4. get the spliced value from the space before the email and the end of the value
- fe=re.sub('[^@.A-Za-z0-9_\-]', '', fe) #5. filter out the random spaces and any other characters that are not acceptable for an email value.
- if (len(fe)<4):#5. determine whether the spliced value is an email or not
- result=value
- else: #if not, print out the the unspliced value
- result=fe
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement