2

I'm using Keyboard Maestro on my Mac to perform a regex find-replace in an nvALT document.

The Keyboard Maestro part of it is not that complicated. It just copies selected text from nvALT, performs the find-replace, and then pastes the text.

I can capture line breaks, but can't seem to put them back in. For example, if I take the text

penguin
horse
robot

Setting the "find" string to

(?m)\n

and the "replace" string to

\n

Then I get

penguinnhorsenrobot

Obviously, the query is seeing and finding line breaks. I can't figure out what I'm doing wrong.

Thanks

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125

1 Answers1

1

Keyboard Maestro supports backreferences, so you can use those to solve your problem.

You can set the 'search' string to

(?m)(\n)

and the 'replace' string to

$1

to get what you want.

Here's an example on regex101.com.

Chirag Bhatia - chirag64
  • 4,430
  • 3
  • 26
  • 35
  • Hi @Chirag64, thanks. You're right that this would solve the problem for this particular issue, but I'm looking for a more multipurpose solution. For example, a more common use case for me would be removing _double_ line breaks. I can use your solution again, but I'd have to group each line break separately in my query. Obviously that's not a very flexible solution. (Though I sincerely appreciate your help.) I'm really trying to figure out why nvALT doesn't handle this normally. – Jack Brannen Mar 03 '14 at 02:32