Stripping final lines without removing lines between paragraphs

17 views
Skip to first unread message

Robert Story

unread,
May 12, 2023, 12:11:25 PM5/12/23
to TextSoap
In the following example, I'd like to trim all trailing returns/lines (lines 6 & 7) without removing any single lines between paragraphs (lines 2 & 4). With the understanding that the samples will be different each time and so I can't specify line numbers, what would you recommend?

trailing-lines.jpg

Mark Munz

unread,
May 12, 2023, 12:18:50 PM5/12/23
to text...@googlegroups.com
Create a custom cleaner and use a Regex Find and Replace action:
image.png

A couple notes: Options is set to s (default m). This makes ^ $ anchors for the entire text, not just lines.
\n+$ - matches one or more returns (\n) that are at the end of the text ($ anchor).
Because this will also remove the return at the end of the last paragraph, I added \n to put it back.
If you don't want the last paragraph to have a return, then you can leave the replace string blank.


On Fri, May 12, 2023 at 9:11 AM Robert Story <robert...@gmail.com> wrote:
In the following example, I'd like to trim all trailing returns/lines (lines 6 & 7) without removing any single lines between paragraphs (lines 2 & 4). With the understanding that the samples will be different each time and so I can't specify line numbers, what would you recommend?

trailing-lines.jpg

--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/5103c86a-e30d-4fb4-a957-7977f7b03330n%40googlegroups.com.


--
Mark Munz
unmarked software
https://textsoap.com/

Robert Story

unread,
May 12, 2023, 1:48:54 PM5/12/23
to TextSoap
That works...thanks much! Ideally, I'd also like to strip the very last new line so that nothing trails the text (as this throws off vertical alignment when text is in object fields). This looks like something a negative lookahead would handle, but I've not yet figured out the syntax.

Mark Munz

unread,
May 12, 2023, 2:50:04 PM5/12/23
to text...@googlegroups.com
If you want to remove all the returns at the end of the text, leave the replace field blank:

image.png
It shouldn't require a lookahead.

Reply all
Reply to author
Forward
0 new messages