Greg Feiges
Greg Feiges

Reputation: 23

RegexReplace in GoogleSheets To Find Multiple Strings

I have a string such as the following

bells<[email protected]>,bars<[email protected]>, ballots<[email protected]> 

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 [email protected] just fine, but I want to get all three 3 instances.

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

Upvotes: 2

Views: 479

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626689

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.

Upvotes: 1

Related Questions