Remove all characters after a new line

I am pulling content from an API (JSON) and I want to remove everything that’s after a new line. This is a snippet of what it would look like in the API:

...
"text": "In pellentesque massa lorem, nec feugiat risus dignissim ac.\n\nMorbi justo felis, scelerisque vitae ligula sit amet, porttitor molestie sapien. Pellentesque tristique nisl et leo hendrerit consectetur.",
...

When I use the Text element on Bubble to display the data, this is what it looks like:

In pellentesque massa lorem, nec feugiat risus dignissim ac.

Morbi justo felis, scelerisque vitae ligula sit amet, porttitor molestie sapien. Pellentesque tristique nisl et leo hendrerit consectetur.

What I want to do is only display the first line from the text field, so it can look like this:

In pellentesque massa lorem, nec feugiat risus dignissim ac.

I was thinking about using :extrax with Regex function, but I haven’t been able to find the right regex. Unless, there is a better method of handling this.

[^\n] and if you were to repeat the task in say a multiline text box, into repeating group for instance [^\n]+ should do the trick.

1 Like

Excellent, using [^\n]+ worked, thank you. I also added :first item because it would still show the remaining content after the first line but in commas, for example:

Using just the :extrax with Regex

In pellentesque massa lorem, nec feugiat risus dignissim ac.,Morbi justo felis, scelerisque vitae ligula sit amet, porttitor molestie sapien. Pellentesque tristique nisl et leo hendrerit consectetur.

Using :extrax with Regex:first item

In pellentesque massa lorem, nec feugiat risus dignissim ac.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.