Remove strings in a line in multiline Excel cells if they do not start with a certain string

I have a column of Excel cells that follow this format (the random strings are not in a fixed order). Strings that don't start with a certain string need to be removed.

randomstringA text_that_needs_to_be_kept1
text_that_needs_to_be_removed1
randomstringB text_that_needs_to_be_kept2
randomstringA text_that_needs_to_be_kept3
text_that_needs_to_be_removed2

I want the cell's output to be this (linebreak must be kept):

text_that_needs_to_be_kept1

text_that_needs_to_be_kept2
text_that_needs_to_be_kept3

And not this (linebreak got removed):

text_that_needs_to_be_kept1
text_that_needs_to_be_kept2
text_that_needs_to_be_kept3


Read more here: https://stackoverflow.com/questions/67375493/remove-strings-in-a-line-in-multiline-excel-cells-if-they-do-not-start-with-a-ce

Content Attribution

This content was originally published by Xyd at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: