You need to sign in to do that

Don't have an account?

Tasia Demuth 4

# Do any of you know of a formula that will grab the emails from a format like this: John <john@esource.com>, Nick <nick@esource.com>

I am looking for a way to copy the emails from a calendar event and returning just the email string, rather than the name and email string.

Ideally it would look like: john@esource.com,nick@esource.com

I have been playing around with the TRIM and SUBSTITUTE functions but have been struggling to get it just right.

Any help would be greatly appreciated.

Thanks!

Tasia

Ideally it would look like: john@esource.com,nick@esource.com

I have been playing around with the TRIM and SUBSTITUTE functions but have been struggling to get it just right.

Any help would be greatly appreciated.

Thanks!

Tasia

SarvaniHi Tasia,

Please refer below sample where its extracts only emil from part from give string. Though I am not sure where exectly you are using this might help Hope this helps! Please mark as best if it does

Thanks

Tasia Demuth 4Oh that is very helpful! I will play around with it and see what I can do!
Thanks,
Tasia Alain CabonWith a formula, it is very difficult because each new email in the list increases the calculation of the offset ( positions just beyond the next "<" and ">" ).

First email and found first "<" ( no offset for the FIND )

Second email and found second "<" needs an offset ( FIND( '<',email__c)+1 ) repeated in each FIND ( searched text, source text , offset )

The formula works for just two emails (very restricted use). Apex is a better option like above but you also need a trigger.

Tasia Demuth 4Thanks, Alain!
You are always so helpful. If it only works for two emails, then I agree Apex seems to be the better option. I will keep investigating and playing with this. It is kinda a fun but challenging puzzle.
Thanks!
Tasia Alain CabonHi Tasia,

More emails could be found with a formula but since the third email the formula becomes very complicated and for the fourth or fifth email that could already exceed the compiled maximum size permitted for a formula so it is not an interesting option excepted if you have always one or two emails.

In Apex, you can get hundreds of emails (possible for a mailing list) because there are the split method and methods for the regular expressions that are the main missing methods for the formula field.

As soon as we could write at least in a formula: SPLIT( email__c, "," , 1 ) for getting the first email and SPLIT( email__c, "," , 2 ) for the second one, etc, the problem will become a easier task but that is still missing.

Alain CabonWith Apex, you can also regular expressions with capturing groups.

String regExp = '

<(.+?)>'; // between the parenthesis, there is the first capturing group (1)..+?: means any characters (the period) (at least one (+)) after ( < ) up to the character after the '?' here ( > ) (the parenthesis are not used)Tasia Demuth 4Oh interesting. That could be useful for this use case. Would this allow for up to 100 emails to be grouped and trimmed? Alain CabonThere is no limit here because it is in Apex.

That is the real interest of the regular expressions indeed because there is an iterator ( m.find() ) that will browse all the emails that mach the format ( < anything between > )

Tasia Demuth 4Okay cool! That would probably be the best solution then. I will keep working on it.
Thanks again!
Tasia Alain CabonOtherwise, there is the simple: String semail[] = emails.split(','); and you browse each email of the array using the first apex solution for the reformatting. It is almost the same. It is just to know an alternative but we use the two solutions alternately.

The problem of the regular expressions is to understand what they are doing exactly contrary to indexOf and substring.

The regular expressions are usefull for complicated extractions where the uses of indexOf and substring become many in a code with many tests.