Forum Documentation Showcase Pricing Learn more

Text to url slug with regex

Hello fellow Bubblers!

I am trying to create a slug from a text value. Take for example a blog post titled: This is My Blog Title!!!

The slug should be something like: this-is-my-blog-title

Space and punctuation stripped out.

I’m trying to use regex to make this happen. Here is where I got so far.

  1. First I’m making the entire string lowercase
  2. Find and replace ! with null space
  3. Find and replace with regex expression [^0-9a-zA-Z]+

The issue I’m running into is that I still end up with the “-” at the end of the slug.

Does anyone have experience with the sort of issue?

There’s a good little snippet of code here that should help you (along with some other pointers in the thread that follows):

In case it’s not obvious what this does:

  • Convert your string to lowercase
  • Regex 1 replaces spaces with dash
  • Regex 2 Removes non word characters
  • etc.

You can do all of this in Bubble equivalents. (As another poster in that thread points out, there are JS functions for trimming, etc. Bubble has a remove whitespace operator.)

@AliFarahat has a plugin for this


Yes its there! Thanks. If its not working as expected message me


@keith, @danielowega, @AliFarahat Thanks for your responses and help!

I decided to go with the @AliFarahat’s plugin for two main reasons.

  1. It’s easier
  2. I may end up using the Hero Sizing and Distance functions

My solution now involves Slugifying the input, then when creating/updating the object, using the Slugify output to save the slug to the DB.