Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a document(.doc) with hundreds of email id's in it placed randomly in the text. How do I isolate the email ids, so that I can export them to my Gmail Contacts?

I would like a solution to this using regular expressions on Writer or using the search feature on Word or by any other method.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

A complete, thorough solution for this would be a formidable challenge with any regex-supported environment, Word/Writer the more so. See this post for why regexes are not a panacea for all text/email-matching problems that come up. That disclaimer out of the way, let's see if a practical solution is in reach...

For me, the practical solution would probably involve using regexes at some point in the process, but not without first fretting over the existence of such possibilities in the data: bob@company.organica@yahoo.com... If emails really were randomly distributed in a text file, one would need to account for that case - the possibility of finding 2 emails next to each other, with no obvious separator. Is it bob@company and organica@yahoo.com or is it company.organica@yahoo.com with the initial text bob@ just gibberish? I'm guessing similar convincing examples can be found.

A reasonable first stab at the problem might be somewhere along these lines:

  1. find an email-matching regex I can live with (no such thing as the perfect one!)
  2. find all emails in the text file using that regex, and place them on new lines, appending some kind of marker text like 'w00t' at the beginning
  3. order the file (using :order command), separating all the 'w00t' lines, the ones with the emails we've found, from the rest of the unmatched junk
  4. go through the unmatched lines one by one to ensure you are not missing an real data there. If you find that you are, go back and modify the regex in #1 or manually extract those emails before continuing with step #2. Otherwise, there is the danger that you are splitting an email (which did not match the regex) into pieces, saving one part and throwing away the other.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.