2

I have a string such as the following

bells<1@gmail.com>,bars<2@gmail.com>, ballots<3@gmail.com> 

I would like to extract the e-mail addresses out of this string comma separated

Formula using is the following

=REGEXREPLACE(A7,"\<(.*?)\>","")

However, the results I get are the following and opposite of what I was expecting

bells,bars, ballots

This formula =REGEXEXTRACT(A7,"\<(.*?)\>") results in 1@gmail.com just fine, but I want to get all three 3 instances.

Any help and explanation as to why the regex "<(.*?)>" isn't working.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

1

You can use

=REGEXREPLACE(A1, "[^<]*<([^<>]*)>(,?)", "$1$2")

See the regex demo. Details:

  • [^<]* - zero or more chars other than <
  • < - a < char
  • ([^<>]*) - Group 1: any zero or more chars other than < and > chars
  • > - a > char
  • (,?) - Group 2: an optional , char.

$1 and $2 refer to the values captured with Group 1 and 2 respectively.

player0
  • 124,011
  • 12
  • 67
  • 124
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Thanks this worked well and was able to add additional e-mails which worked as well. Thanks for answering and the key for me was understanding how to use the capture groups in the regexreplace. Thanks again for the answer – Greg Feiges Feb 06 '22 at 02:58