My goal is to get something like this goal. For every new line after the 1st one if it doesn't start with a ">" I want it to be numbered (starting from nr. 1 on), as for the lines that start with ">" - to just return those without numbering them. I've tried to insert strings with the numbers See here, the problem is I don't know how many lines I might have that don't start with ">" and if these are intercalated with the other ones - so I can't really "hardcode" the string into the formula, as I did. Any solutions? thanks.
Asked
Active
Viewed 157 times
1 Answers
0
try:
=ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, IF(REGEXMATCH(""&
SPLIT(A2, CHAR(10)), "^>.*"),
SPLIT(A2, CHAR(10)), TRANSPOSE(MMULT(TRANSPOSE(TRANSPOSE((SEQUENCE(1, COLUMNS(
SPLIT(A2, CHAR(10))))<=SEQUENCE(COLUMNS(
SPLIT(A2, CHAR(10)))))*NOT(REGEXMATCH(
SPLIT(A2, CHAR(10)), "^>.+")))), TRANSPOSE(SIGN(NOT(REGEXMATCH(
SPLIT(A2, CHAR(10)), "^>.+"))))))&". "&
SPLIT(A2, CHAR(10)))))

player0
- 124,011
- 12
- 67
- 124
-
that seems to work indeed, would you care to break it down for me a little bit? – Debora S. Sep 07 '21 at 13:59
-
@DeboraS. sure, see: https://docs.google.com/spreadsheets/d/1GAsrnCq9L6Aentbpurl-c9NuSIpiIjiyTYHjox_HA64/edit#gid=0 – player0 Sep 07 '21 at 22:41
-
That's really helpful! But what if I wanted it to start the numbering (sequence) from the 2nd line on (so: abc (\n); 1. xxx; etc.) , as I was able to do in my formula. I can't quite get how to do that with yours. – Debora S. Sep 08 '21 at 12:10
-
@DeboraS. you can do it like this: https://i.stack.imgur.com/l3fQj.png – player0 Sep 08 '21 at 21:35