1

Hi i was looking for a way to verify the domain with a provided email address The domain names can be http://www.test.free.com http://www.free.com.au http://www.free.com.au.org http://www.free.com.org or there can be a domain name with any number of sub sub domains and any number of verifications.

the verifying email should contain the domain and this is what i wrote so far

if domain_url is not None and verification_email is not None:

    logging.info('==============================')
    logging.info('BOTH WERE NOT NONE')
    logging.info('==============================')

    domain_email = verification_email.split('@')[1].split('.')[0]

    logging.info('==============================')
    logging.info(domain_email)
    logging.info('==============================')

    verify_domain_url_list = domain_url.split('.')

    if len(verify_domain_url_list) == 4:
        verify_domain_url_list.pop()
        verify_domain_url_list.pop()
    if len(verify_domain_url_list) == 3:
        verify_domain_url_list.pop()


    verify_status = domain_email in verify_domain_url_list

    if verify_status:
        return 'yes'
    else:
        pre_domain_address = verify_domain_url_list[0].split('//')[1]
        if pre_domain_address is not None and \
            domain_email in pre_domain_address:
            return 'yes'
        else:
            return 'no'
    return 'no' 

but this not matching for all the possibilities. can any one give a help?

not 0x12
  • 19,360
  • 22
  • 67
  • 133

1 Answers1

1

You can do it like this, just add the new domains inside the parenthesis.

verification_email = 'fed@test.free.com'
pattern = r'.*@(test.free.com|free.com.au|free.com.au.org|free.com.org)$'

import re
if re.search( pattern , verification_email):
    print('yes')
    # or on your case, return 'yes'

https://github.com/fedmich/StackOverflow-answers/blob/master/python-11220230/regex.py

fedmich
  • 5,343
  • 3
  • 37
  • 52
  • I believe he was more looking for some type of for looped check on the domain itself and if it was possible... adding a new domain for every domain out there would be almost impossible as there are hundreds if not thousands of domains made every day. – gabeio Jun 28 '12 at 03:50
  • 1
    Well if that is the case. rather than managing for loop, he could just customize the pattern as he need it to be .*(free|hotmail|blocked).* this would block domains that has free, hotmail, or blocked in the url of the domain. – fedmich Jun 28 '12 at 03:59
  • I actually meant that... I'm just really tired if you could post the pattern for all possible emails and domain names that is probably what he is looking for... – gabeio Jun 28 '12 at 04:02
  • Yeah, I understand its endless possibilities of domain. But as he said, he's looking for a pattern. – fedmich Jun 28 '12 at 04:06