Insert new line using Search-and-Replace in TW Commander

Trying to insert a couple of lines at the top of multiple documents.

I have managed to find the top of the document, but in inserting the text I am running into a problem adding a ‘new line’ in-between the two lines, and at the end of the two lines.

Tried many combinations of \n and \r etc. (on a Mac) with and without quotes and apostrophes, but so far none of the combinations work. The text is inserted, but all on one line.

So how do I insert the new line character?

1 Like

Temporarily fixed by using <br /> but would still like to know…

Right.

The reason it fails is that S-N-R in Tiddler Commander does not support meta-characters in REPLACE, though supports them all in MATCH.

There is a trick, if you are familiar with regex, you can use with a “capturing group” to grab an “\n” from the original and then use that capture in the replace.
Here is an example (using plain text) …

Match: “^.+(\n)” ------ set SNR to “first match”

Replace: “New para ONE.$1$1New para TWO.$1$1$&

In the replace “$1” is the captured “\n” re-inserted as often as needed. And the “$&” the full string of the original match.

The result should look something like this …

I hope how this works is clear?
Ask if not and I’ll make a demo.
The question was an interesting one!

Best TT

4 Likes

I have often used the $1 in replace regex, but in this particular example I was simply moving the cursor to the beginning of the document and inserting text, so there were no new line characters to capture to begin with.

SNR in Tiddler Commander, as I wrote before, does not support “Replace” meta-characters other than “$x”.

I might be able to give a workaround for your current issue if you provide …

1 - Example text of “before”

2 - Example text of “desired result”

Best wishes, TT