Best way to parse string of email addresses

后端 未结 13 2609
悲哀的现实
悲哀的现实 2021-02-14 04:10

So i am working with some email header data, and for the to:, from:, cc:, and bcc: fields the email address(es) can be expressed in a number of different ways:

F         


        
13条回答
  •  误落风尘
    2021-02-14 04:53

    Here is how I would do it:

    • You can try to standardize the data as much as possible i.e. get rid of such things as the < and > symbols and all of the commas after the '.com.' You will need the commas that separate the first and last names.
    • After getting rid of the extra symbols, put every grouped email record in a list as a string. You can use the .com to determine where to split the string if need be.
    • After you have the list of email addresses in the list of strings, you can then further split the email addresses using only whitespace as the delimeter.
    • The final step is to determine what is the first name, what is the last name, etc. This would be done by checking the 3 components for: a comma, which would indicate that it is the last name; a . which would indicate the actual address; and whatever is left is the first name. If there is no comma, then the first name is first, last name is second, etc.

      I don't know if this is the most concise solution, but it would work and does not require any advanced programming techniques

提交回复
热议问题