Forum Academy Marketplace Showcase Pricing Features

Remove the last X no. of characters in string via Regex

Pinning here to save others some googling… I know I can’t be the only one looking for how to achieve this.

This simple regex expression will remove the last x no. of characters in a string.

.{x}$ where x= the no. of characters you want to remove, including spaces.

(Bubble’s current truncate options doesn’t work for variable string lengths.) My use case is abbreviating formatted Google addresses, as the WHOLE address is not necessary for what I need and clutters my UX. I wanted everything except, the 5-digit zip and “, USA”

Using a dynamic expression, I did a find & replace on my formatted address and checked “Use regex pattern” box.

Google’s formatted address: 6910 Fayetteville Rd, Durham, NC 27713, USA
Displays as: 6910 Fayetteville Rd, Durham, NC

Of course you can build more sophisticated expressions and add different qualifiers, but I just needed the basics here.

Here are my reference, fyi.

The board where I found the expression:

A tester to check & build expressions:

A cheat/reference sheet

Happy building :slightly_smiling_face:


Love regex!

This is exactly what I have been spending the past few hours trying to figure out! Thank you for the example and references!

1 Like

awesome. delighted this has helped someone!

Thank you @sharifa !
The Future

Awesome, couldn’t find the right Regex to save myself!