Best answer

Deleting characters from the end of a URL

  • 23 July 2020
  • 3 replies
  • 1579 views

Userlevel 1

I need to delete the last 8 characters from a URL being generated. The URL is different in length every time so you cannot just do a character limit. It does always end with the same 8 characters.

 

Example URL: 

 

https://inspiredgo.myshopify.com/cart/update?updates[31481855967274]=2&updates[31449688637482]=1&updates

 

I need the “&updates” on the end of the URL to be deleted or segmented automatically and cannot figure out how to do that. The final URL result should be:

 

https://inspiredgo.myshopify.com/cart/update?updates[31481855967274]=2&updates[31449688637482]=1

 

Any ideas? Thank you kindly :)

icon

Best answer by PaulKortman 23 July 2020, 22:20

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +10

@drucki This is a great use case for pattern matching (or regex) and you can find this in the Formatter by Zapier app. 

 

Add a Formatter by Zapier Action step, choose Text and Extract Pattern then fill it in like so:

The key or difficult part is the Pattern using Python Regular Expressions. I tested this out and it seems to work:

(.*)\&updates$

Those characters are explained:

  • the parenthesis “()” mean return anything inside here, this is the pattern I want to return
  • the dot “.” is any single character
  • the asterisk “*” means 0 or more of the dot (so in combination it means unlimited number of characters)
  • the slash “\” is to escape the &
  • the &updates is the part you want to match/find and exclude from the returned result
  • the dollar sign “$” signifies the end of the string or value passed to it. 

So it reads: Match/find everything up until the last character only excluding the “&updates” at the end of the string. 

 

Test it out and see if it works for you.

Userlevel 1

AMAZING! Thank you so much @PaulKortman this worked perfectly. You just saved me hours of frustration Paul, you’re the man :grinning:  

Userlevel 7
Badge +10

Happy to help! Enjoy!