Regex pattern to remove URL parameters/UTM

Hi all,

I need some help finding and removing any page path/UTM/querystrings from URLs using a Regex pattern.

For example, if a user visits using https://yourdomain.com/facebookpixelid?appid=test I’d like to remove that dynamic data after https://yourdomain.com including the first ‘/’ so that we just get the root domain with https:// and nothing after that.

Any idea the Regex to do so? @NigelG is this something you know about?

Thanks
Reece

1 Like

Thanks Nigel, so is it just the ^(?:https?://)?(?:[^@/\n]+@)?(?:www.)?([^:/?\n]+) in the Regular Expression input that I copy paste into Bubble? This is well beyond my knowledge here…

1 Like

Yes, that is correct.

1 Like

Thank you!

Regex Nigel!

I’m trying to do the opposite of this and cannot seem to figure it out.

I’m trying to get everything AFTER http://www. or https://www

I mean, it works on regex101, but its got a non-matching and a matching group, and I’m not sure how to make it work in bubble.

It is returning the whole string in bubble.

(?:^http.*://www.)(.+)

Keep it simple: You desire to remove the protocol identifier, which is everything from the start thru “//”. Find that and replace it:

Yields:

image

Now it doesn’t matter if the protocol is http://, https://, ftp://, some_other_protocol_nobody_uses://, etc.

3 Likes

thanks keith!

1 Like

Hey all - I wanted the following and @NigelG kindly helped me out in a private message. I wanted to share for all.

Goal = Extract the query string but keep more than just the root domain

Example: https://www.imdb.com/title/tt5491994/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=12230b0e-0e00-43ed-9e59-8d5353703cce&pf_rd_r=68MZSCC1NRKFNE55V64M&pf_rd_s=center-1&pf_rd_t=15506&pf_rd_i=toptv&ref_=chttvtp_tt_1

Desired output: https://www.imdb.com/title/tt5491994/

Required regex = ^[^?]+

I realized what I actually needed to do was throw away everything from the “?” on. I managed that with a regex find and replace as follows:

Find: ?(.*)
Replace: [nothing]

2 Likes

This may be helpful to others.

2 Likes

https://regex101.com/ has been the tool that has finally enabled me to understand regex and make my own patterns that work for me.

breaking through some search barriers as I type this and having so much fun doing it, that I had to give you an extra nod on here for sharing it.

:beers:

2 Likes

Hello,

So reading through this thread again I couldn’t figure how to work with a string like SULFW.M.W.HW.01

What I need is the M.W.HW.01 and remove the SULFW.

The number of the characters before the first dot varies.

I tried using the solution from @keith but ^.. (as in ^.// to remove the http// from a url) results in the entire string being removed.

Does anyone have a suggestion?

image

image

Thanks,
George

Solution to this specific question is:

^[^.]*.

I found this thread because I was having an issue that I reached out to Bubble support on. The issue is that I wanted to use a conditional that was “This URL is Website Home URL” for navigation purposes.

This should be relatively straight forward, but Bubble actually is tracking our users through the use of a ‘resume’ parameter which we don’t see in the URL except for a brief moment when the page is being navigated (at least with the go to page action).

What this results in on a home page (index page), the ‘this url’ will look like Web Hosting, Domain Name Registration - MyDomain.com

and that of course would not match the ‘website home url’ which is https://www.mydomain.com/

Bubble support told me to use a regex pattern to remove the resume parameter for my conditional to work properly.

Thanks to @GB44 for posting the pattern he used.

This works for me to remove the resume parameter from the URL.

Thanks for sharing this, @GB44 and @NigelG . I just added this in my app, but to get the regex to work I had to add “” to escape the “?”.

Find: ?(.*)
Replace: [nothing]