Text column to remove line breaks & new paragraphs?

Is there as special text column that can ‘clean’ a text string to remove text formatting, e.g. line breaks and new paragraphs?

I am trying to export data from a Glide Data table by copying the contents of a Template column to clipboard. The template column is fed by content from a few different columns. It works well except when a user has inputted some text that includes line breaks or new paragraphs! If they do, pasting into excel disrupts the formatting.

(Not interested in other ways to export data at this stage!)

I haven’t tested with things like line breaks, but I would assume it handles them.

Yup, tried that. no luck.

oh, really?

Okay, next option would be the Extract Matching Text plugin with an appropriately crafted regex. Are you familiar with regex, or would you like some help with that?

^\s*(.*)\s*$ should do the trick.

Actually, the Trim Whitespace plugin works for me. Can you share some examples of strings that it doesn’t work for?

Oh thanks for taking the time Darren.

An example of some tricky text:

"We need to engage Urologists and not just Oncs.

Office-based urologists carry out cystoscopy or transurethelial resection and refer patients with suspected UC to hospital."

In my version, the whitespace column does nothing to that text. The paragraph breaks remain in tact…

oh, I see. So you actually want to condense line breaks into a single white space, yeah?

yeah, Trim won’t do that. You need a regex. It’s time for my little boys bedtime story now, but I can come back with an appropriate regex a bit later…

1 Like

I will try one other thing first, see if I can use a template column to replace all paragraph breaks…

The template option didn’t work…!

Replace All will do it.

The replacement value is just a single space.
This won’t get rid of leading/trailing single spaces, but you could then run that through Trim to clean those up.

2 Likes

I will try this (need to run for 2 hours first though) but THANKS^6

Excellent Darren - THANK YOU.

Your proposal to use the ‘Replace All’ text column works well. This column accepts special rich text format arguments. I could literally type enter (new line) as the argument to replace and it works perfectly.

1 Like

Cool!

Just one thing to be aware of with that approach… if you’re using a literal new line as the argument, and a space as the replacement value, then it will replace every new line with a space. So for example, if you had a block of text that contained 6 new lines, then it would replace that with 6 spaces. Which may or may not be what you want.

If you’d want those 6 new lines condensed into a single space, then I’d recommend using the regex pattern as per my example, ie: \s+

\s matches any white space character, and + is quantifier that means “match 1 or more times”

Thanks for the advice. To be clear, I didn’t use any special characters like \s+. I just pressed enter.

Your example of \s+ is for spaces. What is the equivalent for a new line?

Regards,
Simon.

@Darren_Murphy knows better than me, but it might be one of \n (new line) or \r (carriage return).

Yes, I understand that.

The equivalent for a new line is exactly the same. As I explained above:

The definition of any whitespace character can vary depending on the regex engine, but it usually includes: space, tab, newline, carriage return & vertical tab.

Your response suggests that I didn’t do a very good job of explaining, so I’ll try again.

Let’s go back to your earlier example, but add a few extra carriage returns:

"We need to engage Urologists and not just Oncs.






Office-based urologists carry out cystoscopy or transurethelial resection and refer patients with suspected UC to hospital."

Here is what that looks like in the Data Editor:

Screen Shot 2022-01-21 at 9.12.59 AM

Now, assuming that I understand correctly, what I believe you are doing is using the Replace All plugin and replacing all occurrences of a newline with a single space. So the column configuration probably looks something like this:

When you apply that approach to our extreme example above, this is the result you will get:

Screen Shot 2022-01-21 at 9.14.37 AM

Notice that block of empty space after the word Oncs?

That’s because we have replaced 6 newlines with 6 spaces.

If that’s okay, then fine. But if you’d rather not have that odd looking empty space, then that’s where the regex pattern comes in. Here is what that looks like:

And here is the result:

Screen Shot 2022-01-21 at 9.15.43 AM

When you use \s+ as the “Replace This” value, and a single space as the “With This” value, that essentially means: “replace any and all sequences of one or more white space characters with a single space”

3 Likes

\n is a new line, and \r is a carriage return.
\s is a “superclass” that covers both of the above, and more.

A good analogy would be:

\n = oranges
\r = apples
\s = fruit

3 Likes

That’s super clear, thank you!

My bad. You had already explained it perfectly. For some reason when I first tried the \s+ syntax it didn’t seem to work. Not sure what dumb thing I was doing since when I tried again today, it worked perfectly.

The fruit analogy is great and is super useful! Thank you again.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.