On one of my recent projects, I had to compare active users against an Outlook distribution group. Talk about a nightmare! I’m not an Exchange admin so I couldn’t quickly export the group as a CSV and extract the required information.
After spending a bit of time in Outlook to see if groups could be exported I went in another direction. I wanted REGEX to solve my problems. Yes, the strange, confusing, mysterious, and powerful REGEX. And I wanted Notepad++ to do it for me. After spending a bit of time looking for the right solution, I found it.
So, dear reader, here’s how to extract just the emails from an Outlook distribution group.
- Open a new Outlook message and type in the distribution group name.
- Expand the distribution group so that you see all of the members.
- Copy all of the members to Notepad++. You will get something like the following:
- Our next goal is to get the email addresses on a separate line so we can mark them and then remove all other content. Start by pressing CTRL + H (find and replace). Under Find what type the left bracket ‘<‘. In the Replace with type in ‘\r\n’ which will create a new line break. Ensure to select the Search Mode ‘Regular expression’. Click Replace All. You should see the following:
- Perform the same step as described above but using the right bracket ‘>’.
- Now, we will use REGEX to find the email addresses and mark them.
- In the Replace dialogue box click the Mark tab. In Find what paste the following REGEX:
- Ensure the Bookmark line is enabled. Click Mark All. It should look something like this:
- Only one more step to go! Click Search > Bookmark > Remove Unmarked Lines.
You’re done! The final result is a nice looking list that you can copy and paste into Excel or Google Sheets and use conditional formatting to compare against another list (or whatever you needed the emails for in the first place)!