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: regex - How to remove the last 13 (or n) characters of every line using Notepad++ - Stack Overflow

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!

Thank you so much

Awesome, after weeks of fooling around with Bubble, this is the first time I’ve logged in, just to make a comment. Had to say THANK YOU for helping me solve a problem I simply couldn’t figure out with “Truncate to” and other operators! Thank you!

Wonderful. So glad it saved you some frustration!

AGH thank you! I spent way too long trying to find this and here you are! appreciate it.