Home > Net >  RegexReplace in GoogleSheets To Find Multiple Strings
RegexReplace in GoogleSheets To Find Multiple Strings

Time:02-06

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.

CodePudding user response:

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.

  •  Tags:  
  • Related