Google Spreadsheet actually has regex methods. There are 3 methods:
REGEXEXTRACT(text, regular_expression) - Extracts matching substrings according to a regular expression. Example: REGEXEXTRACT("Needle in a haystack", ".e{2}dle")
REGEXMATCH(text, regular_expression) - Whether a piece of text matches a regular expression. Example: REGEXMATCH("Spreadsheets", "S.r")
REGEXREPLACE(text, regular_expression, replacement) - Replaces part of a text string with a different text string using regular expressions. Example: REGEXREPLACE("Spreadsheets", "S.*d", "Bed")
However, because I don't really know how to use regex, I'll show you how I would do it using SPLIT
. This will work even if the numbers aren't separated by a specific character (i.e. space) as shown in the example:
=SUM(SPLIT(A1,CONCATENATE(SPLIT(A1,".0123456789"))))
Seems to do the job.
Key for the sort is the notation of the digits in the text (String #). These are sorted alphanumerically, meaning that 9
is higher than 25
when sorting descendingly. This can be resolved by squeezing in a zero to all digits ranging from 1 to 9. See formula I constructed.
Formula
=SORT( // range
UNIQUE( // range
ARRAYFORMULA( // array_formula
IF(
MID( // logical_expression
A2:A, // string
9, // starting_at
1 // extract_length
)="/",
REPLACE( // value_if_true
A2:A, // text
8, // position
0, // length
"0" // new_text
),
A2:A // value_if_false
)
)
),
1, // sort_column
TRUE // is_ascending
)
copy / paste
=SORT(UNIQUE(ARRAYFORMULA(IF(MID(A2:A, 9, 1)="/",REPLACE(A2:A, 8, 0, "0"), A2:A))), 1, TRUE)
Screenshot
Explained
The MID
formula separates the 9th character from the string placed in A2:A
. If it matches a /
, then use the REPLACE
formula to insert a 0
at position 8, by using zero as start position. If no match has been found, simply show the unaltered range A2:A
. All is wrapped inside an ARRAYFORMULA
to take on ranges instead off one cell. The altered range is then fed to the UNIQUE
formula that will show only unique entries. This range is sorted by the SORT
formula, using the first column of the range (and the only one) and sorted ascendingly.
Best Answer