Remove Blank Line - What Am I Missing

I use the following snippet to help remove blank lines from text Press Releases we are sent. These work very well

{=replaceregex({clipboard}, "(\n\s)\s{1,}", "$1", "sg")}

However there is one site that for the life of me I cannot work out why the blank line removal is not working.

  1. Goto this site

https://pressroom.warnermedia.com/us/media-release/hbo-max/whats-new-hbo-max-march

  1. Scroll down to this section

TITLES COMING TO HBO MAX IN MARCH:

  1. Copy several of the shows/titles into the clipboard

  1. Run the snippet.

What I get is this

A Dangerous Method, 2011

Night at the Museum: Secret of the Tomb, 2014 (HBO)

Basic, 2003 (HBO)

Beatriz at Dinner, 2017 (HBO)

Best of Enemies, 2015 (HBO)

Bloodsport, 1988 (HBO)

What it should be is this

A Dangerous Method, 2011
Night at the Museum: Secret of the Tomb, 2014 (HBO)
Basic, 2003 (HBO)
Beatriz at Dinner, 2017 (HBO)
Best of Enemies, 2015 (HBO)
Bloodsport, 1988 (HBO)

Anyone able to spot what's going on here.

Why do you have the first \s in the regex? If you remove the \s from within the parenthesis it should work:

{=replaceregex({clipboard}, "(\n)\s{1,}", "$1", "sg")}

1 Like

Ha thanks @scott , I've no idea. I think I copied it from another snippet :slight_smile:

That works great. Thanks for spotting the error, much appreciated

Hi, in continuation of this topic, how do I remove line break from paragraphs.

Here is source:
Line 1 Line 1 Line 1
Line 2 Line 2 Line 2
Line 3 Line 3 Line 3

My desired output:
Line 1 Line 1 Line 1 Line 2 Line 2 Line 2 Line 3 Line 3 Line 3

Kindly help. Thank you in advance

Hi @Pratik_Shah ,

This is what I use. It takes what's in the clipboard and removes the blank lines. There may be better ways of doing this and you would need to test it on your setup.

Hope this helps

{=replaceregex({clipboard}, "\n", " ", "sg")}

Note: The sg flags are explained below taken from the help docs.

When the multi-line flag ("s") is set, the "." special character will match multiple lines.
The global flag ("g") is only supported in replaceregex. When it is set, the search will replace all matches instead of only the first match.

1 Like

Thank you for the detailed reply.
However, It is not working actually in my case actually.

If you can give some more details/examples/links I will try to help.

Here's the snippet with your example

{text="Line 1 Line 1 Line 1
Line 2 Line 2 Line 2
Line 3 Line 3 Line 3"}

BEFORE
{=text}

AFTER
{=replaceregex(text, "\n", " ", "sg")}

1 Like

Not sure why but its not happening at my end. I guess the source text may be with some different alignment.

Andy's answer is correct, but if you're on Windows, and getting data from the clipboard command, your newline endings will be \r\n instead of just \n. Try this:

{=replace(replace({clipboard}, "\r\n", " "), "\n", " ")}

This will first remove Windows-style newlines, and then remove regular newlines as expected. Let me know if it works for you.

1 Like

Ah yes, I'm on Fedora :slight_smile: Thanks for updating Guarang

Thank you so much. This worked.

1 Like