RegEx Questions

The Text


My RegEx so far

I have 3 questions, ordered in importance.

  1. Separate emails and number into a different variable
  2. I don't care about the title, i just want the "Bill Gates Foundation", how do I remove " at" and everything before it?
  3. This isn't super important but for some reason adding another \n at the beginning messes everything up instead of eliminating the first blank row and variable.

edit: all questions are solved now

I presume you're looking for this regex to work with multiple instances of text like this? If that's the case, then just to make sure, are all these instances always going to be formatted like this? I.e. "Your contacts are ready" at the top, followed by a few lines of white space, followed by the contact's name on one line, their title and company on the next with the company name always preceded by "at", and their phone number and email together on the following line, with the number coming first and the email coming second? If there are any variations in this data that don't conform to the formatting I've just described, I'd ask that you show as many as you can here so that the final regex can properly account for all of them (and more importantly, so it only has to be written and tested once :slightly_smiling_face:)

Also, it would be great if you could provide the actual text you're working with, not just a screenshot, so we can copy it without having to type it up ourselves.

Yep multiple instances, same text everytim! In fact my next question after I sort out these is how to repeat this with 100 of these snippets within the same variable, using the "for each" loop i imagine.

Only irregularities are sometimes the position title isn't there and it's just "at bill gates foundation" and sometimes there's only an email or only a number and not both. However that's pretty easy to account for by setting up 3 different if thens using the existence of lack of existence of ( and @ characters.

I managed to solve # 1 btw, probably an overkill solution but managed to find regex that finds an email and then just replace it with nothing to create a phone number variable.

Here's the text ( there should be 2 empty rows inbetween "your contacts are ready" and the name

Your contacts are ready

Bill Gates
Co-Chair & Co-Founder at Bill Gates Foundation
(800) 800-8000 bill@billgates.com

Solved #3 now

Went into the variable and saw there was a extra tab in there so this worked

Your contacts are ready\n\n\t\n\n?(.*)\n\n?(.*)\n\n?(.*)

Figured out the repeating for each regex match as well. I'm sure there's a better way to do this using the for each action but I'm still learning how it works. What I did is set up and until loop, and did a search and replace at the end of the loop that uses name as an anchor to delete the previous 3 rows including the "Your contacts are ready". The next time it loops through, the match it just worked has been deleted so it matches with the next one and does that until there aren't any more.

edit: and solved #2 as well, not sure what the regex is for deleting everything before at and at but figured out how to delete everything before at and then just added a regular search and replace for "at"

Sorry I couldn't respond sooner, but I'm glad you managed to figure out solutions to everything on your own! As long as the macro is doing what you want quickly enough for your tastes there's no one right way to go about it, so feel free to feel good about your accomplishment here :smile:

1 Like