Sub topic 2
Combining Values into One String with JOIN
This chapter assumes you can enter formulas, reference cells and ranges, and write text in double quotes inside a formula. You should also know what a function argument is.
Combining values into one string with JOIN
JOIN is a function that takes a delimiter and a list of values, then returns one string. The delimiter is the text placed between each value.
=JOIN(", ", "red", "green", "blue")This returns red, green, blue. The first argument is always the delimiter.
Joining ranges and skipping blanks with FILTER
JOIN also accepts a range, such as A2:A10. Blank cells, however, add empty pieces and extra delimiters to the result. FILTER removes them first. FILTER(range, condition) keeps only the rows where the condition is true.
=JOIN(", ", FILTER(A2:A10, A2:A10<>""))Here <>"" means "not equal to an empty string," so only non-blank cells are kept.
Just enough regular expressions
A regular expression, or regex, is a pattern that matches text. Google Sheets uses the RE2 syntax. You need only a few symbols:
\dmatches one digit.\wmatches one letter, digit, or underscore.+means one or more of the previous item..matches any single character.[ ]matches any one character listed inside the brackets.
For example, \d+ matches a run of digits such as 10492.
Extracting the first match with REGEXEXTRACT
REGEXEXTRACT(text, pattern) returns the first part of the text that matches the pattern. If the text has no match, the formula returns the error #N/A.
=REGEXEXTRACT("ORD-10492", "\d+")This returns 10492. The result is text, not a number.
Exercise
Exercise
Cells A2:A4 contain "red", an empty cell, and "blue". What does =JOIN(", ", FILTER(A2:A4, A2:A4<>"")) return?
Show answer
red, blue