I am trying to get a list of all the digits preceding the hyphen in a given line (say, in cell A1 ) using the Google Sheets regular expression formula:
=REGEXEXTRACT(A1, "\d-")
My problem is that it only returns the first match ... How can I get all matches?
Sample text:
"A1-Nutrition;A2-ActPhysiq;A2-BioMeta;A2-Patho-jour;A2-StgMrktg2;H2-Bioth2/EtudeCas;H2-Bioth2/Gemmo;H2-Bioth2/Oligo;H2-Bioth2/Opo;H2-Bioth2/Organo;H3-Endocrino;H3-Génétiq"
My formula returns 1- , while I want to get 1-2-2-2-2-2-2-2-2-2-3-3- (either as an array or concatenated text).
I know that to achieve the desired result, I could use a script or other function (for example, SPLIT ), but I really want to know how I can get the re2 regular expression to return such multiple matches in " REGEX.* " Google Sheets Formula . Something like the option < g lobal - Do not return after the first match " regex101.com
I also tried to remove unwanted text with REGEXREPLACE , without any success (I could not get rid of other numbers not preceding the hyphen).
Any help appreciated! Thanks:)
source share