How can I split text without breaking sentences?

Hi Everyone

I’m building an app which will display a body of text with images after every 80-100 words. I’ve used the split feature, and that has been the best solution I’ve found so far. But it keeps breaking sentences before full stop which just looks untidy. Is there a way I can get bubble to slightly deviate from the word limit to ensure it only adds an image after the closest full stop, rather than in the middle of sentences?

Thanks in advance

R

There’s probably an elegant solution out there, but I would first try to brute force it with regex

Here’s what Raycast AI proposed. It needs testing but could be a starting point.


Here is a regex pattern that splits text without breaking sentences:

/(?<=\w)[.?!](?=\s|$)/

This pattern uses positive lookbehind and positive lookahead assertions to match the punctuation marks ., ?, and ! that come after a word and are followed by either whitespace or the end of the string. This ensures that the text is split at the end of a sentence without breaking up the sentence itself.

1 Like

Thank you. I’m pretty new to bubble, so haven’t had a reason to use regex yet. But will give this a go now. Thanks again

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