Suppose that you want to do this for multiple cells of data in the range A2:A. Clear B2:B and place the following formula in B2:
=ArrayFormula(IF(A2:A="",,IFERROR(TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(REPT(REGEXEXTRACT(SPLIT(A2:A,CHAR(10)),"[^#))]+")&"~",REGEXEXTRACT(SPLIT(A2:A,CHAR(10)),"#(\d+)")*1)),,COLUMNS(SPLIT(A2:A,CHAR(10)))))),"~ ","~"),"~",CHAR(10))))))
This formula should produce all results for all rows where A2:A contains data.
If you only want to process the one cell (say, A2), you can use this version in, say, B2:
=ArrayFormula(IFERROR(TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(REPT(REGEXEXTRACT(SPLIT(A2,CHAR(10)),"[^#))]+")&"~",REGEXEXTRACT(SPLIT(A2,CHAR(10)),"#(\d+)")*1)),,COLUMNS(SPLIT(A2:A,CHAR(10)))))),"~ ","~"),"~",CHAR(10)))))
ADDENDUM (after comments):
The OP realized that I'd left off the sequencing of numbers. This definitely made things quite a bit trickier. However, I was able to write an array formula that should work.
Again, supposing that the raw data runs A2:A, clear B2:B and then place the following into cell B2:
=ArrayFormula(REGEXREPLACE(REGEXREPLACE(TRANSPOSE(QUERY(TRANSPOSE(REGEXREPLACE(IFERROR(VLOOKUP(SEQUENCE(ROWS(A2:A))&"^"&SEQUENCE(1,COLUMNS(SPLIT(A2:A,CHAR(10))))&"*",TRANSPOSE(QUERY(TRANSPOSE(REGEXREPLACE(SPLIT(QUERY(FLATTEN(FILTER(IFERROR(SEQUENCE(ROWS(A2:A))&"^"&SEQUENCE(1,COLUMNS(SPLIT(A2:A,CHAR(10))))&"^"&REPT(REGEXEXTRACT(SPLIT(A2:A,CHAR(10)),"[^#))]+")&"~",REGEXEXTRACT(SPLIT(A2:A,CHAR(10)),"#(\d+)")*1)),A2:A<>"")),"Select * WHERE Col1 Is Not Null"),"~")&TEXT(SEQUENCE(1,MAX(IFERROR(SPLIT(REGEXREPLACE(A2:A,"[^#\d]",""),"#",1)))),"00")&"~","^\d+~$","")),,MAX(IFERROR(SPLIT(REGEXREPLACE(A2:A,"[^#\d]",""),"#",1))))),1,FALSE)),"^\d+\^\d+\^","")),,COLUMNS(SPLIT(A2:A,CHAR(10))))),"~\s*$",""),"~\s*",CHAR(10)))
Is it long? Sure. Does it work? Yes, it should. And being an array formula, it actually saves processing and eliminates the need to drag the formula down as new rows of data are added in A2:A.