Regex to replace all spaces for returns

Hi,

I have a long string of words separated by spaces. I'd like to be able to replace each space with a return character. For example,

here are some words

becomes

here
are
some
words

Is I where using Swift/Python/etc. I'd use a global/multiline search and replace regex (/g). Am I missing the obvious way to this with KM?

Thanks in advance!

Then you'd be using regex needlessly, as this is a straightforward exchange of one string literal for another.

1 Like

Hey @Latency,

In general I prefer to use a regular expression for this sort of job, because invariably there will be more than one space and/or a tab stuck in there somewhere.

-Chris


RegEx ⇢ Replace WhiteSpace with Linefeeds.kmmacros (5.4 KB)

1 Like

Thank you. That is the first thing I tried but I was looking at the result incorrectly. I didn't know about Preferences->Variables. I used a "Display text" actions which always showed it as:

here
are some words

Thanks again!

Awesome - thank you!