Remove Multiple Blank Lines

Almost finished with our AutoKey Script Migration. Got this one which is stumping me.

Need to take the contents of the clipboard, and remove multiple blank lines so they are replaced by a single blank line.

eg this

"Big Rig" - When an old pal of Torres' comes to him - disheveled and bloodied - for guidance amidst an undercover FBI operation and then disappears, NCIS helps track him down. Also, McGee prepares to be a contestant on a popular game show, on the CBS Original series NCIS, Monday, Jan. 23 (9:00-10:00 PM, ET/PT) on the CBS Television Network and available to stream live and on demand on Paramount+*.

REGULAR CAST:

Sean Murray (NCIS Special Agent Timothy McGee)
Wilmer Valderrama (NCIS Special Agent Nicholas "Nick" Torres)
Brian Dietzen (Medical Examiner Jimmy Palmer)



Diona Reasonover (Forensic Scientist Kasie Hines)
Katrina Law (NCIS Special Agent Jessica Knight)
Rocky Carroll (NCIS Director Leon Vance)
Gary Cole (FBI Special Agent Alden Parker) 





Last Line

Would be come this

"Big Rig" - When an old pal of Torres' comes to him - disheveled and bloodied - for guidance amidst an undercover FBI operation and then disappears, NCIS helps track him down. Also, McGee prepares to be a contestant on a popular game show, on the CBS Original series NCIS, Monday, Jan. 23 (9:00-10:00 PM, ET/PT) on the CBS Television Network and available to stream live and on demand on Paramount+*.

REGULAR CAST:

Sean Murray (NCIS Special Agent Timothy McGee)
Wilmer Valderrama (NCIS Special Agent Nicholas "Nick" Torres)
Brian Dietzen (Medical Examiner Jimmy Palmer)

Diona Reasonover (Forensic Scientist Kasie Hines)
Katrina Law (NCIS Special Agent Jessica Knight)
Rocky Carroll (NCIS Director Leon Vance)
Gary Cole (FBI Special Agent Alden Parker) 

Last Line

I tried this

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

Which I though would replace multiple new lines with a single but it does not seem to remove them.

Hi @AndyPage,

Your snippet works fine for me (replaces three or more newlines with two newlines).

Does this snippet produce correct output for you in our dashboard?

{text="a\n\n\n\n\n\n\n\n\na"}
{=text}
{="----------------------------------------"}
{=replaceregex(text, "\n{3,}", "\n\n", "sg")}

1 Like

Hi @Mansur_Kutybayev Thanks for getting back to me.

Yes, your snippet works great but maybe I'm doing something wrong. As when I run it using the clipboard instead of the text = "a\n\n\n\n\na" part it does not remove the lines.

If you copy this

REGULAR CAST:

Sean Murray (NCIS Special Agent Timothy McGee)
Wilmer Valderrama (NCIS Special Agent Nicholas "Nick" Torres)
Brian Dietzen (Medical Examiner Jimmy Palmer)



Diona Reasonover (Forensic Scientist Kasie Hines)
Katrina Law (NCIS Special Agent Jessica Knight)
Rocky Carroll (NCIS Director Leon Vance)
Gary Cole (FBI Special Agent Alden Parker) 





Last Line

Into your clipboard and then run the snippet it dos not appear to do anything.

Works for me even with the clipboard:

Repeating the snippet:

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

Does it work in the dashboard for you? What do you get as an output?

1 Like

Very strange.

When I try that exact snippet from my Dashboard here is my output. As you can see it still has the blank lines.

Could you try this one:

{text={clipboard}}
{=text}
{="----------------------------------------"}
{=replaceregex(text, "\r{3,}", "\r\r", "sg")}

and this one:

{text={clipboard}}
{=text}
{="----------------------------------------"}
{=replaceregex(text, "(\r\n){3,}", "\r\n\r\n", "sg")}

2 Likes

Awesome, the 2nd one worked great. I assume the clipboard is storing my text with \r carriage returns and new lines.

Thank you so much for you help and time.

Note: I signed up as a paying customer today. This is such a great tool.

3 Likes