Forum Discussion
How to extract multiple occurrences of a text enclosed between two same characters
- Oct 28, 2024
I hope this works for you (with the text in A5):
=LET(w, TEXTSPLIT(A5, "!"), n, COUNTA(w), s, SEQUENCE(, n), f, FILTER(w, ISEVEN(s)), TEXTJOIN(CHAR(10), TRUE, f))
Just to add some thoughts on modern Excel. I am coming to be of the opinion that spreadsheet formulas are best presented as Lambda functions rather than having the formula details exposed. In that case HansVogelaar's formula might be
ImportantText1λ
= LAMBDA(string,
LET(
newLine, CHAR(10),
extracts, IFERROR(TRIM(TEXTAFTER(TEXTSPLIT(string, "<<"), ">>")),""),
TEXTJOIN(newLine, TRUE, extracts, "")
)
);whilst mine might be
ImportantText2λ
= LAMBDA(string,
LET(
newLine, CHAR(10),
regex, "[\w|\s]*(?=\<)",
TEXTJOIN(newLine,,REGEXEXTRACT(string, regex, 1))
)
);The worksheet formulas would be
= MAP(notes, ImportantTextλ)Any change to the formula made by the developer need not even be visible to the user (unless they are the same person of course) so the sheet may be updated when one chooses using the AFE (Advanced Formula Environment).
PeterBartholomew1 , nice approach, I like it. I hope, Microsoft team will also improve debug possibilities for LAMBDA formula and the Name Manager dialog window. Currently, it is a kind of black box.