Skip to main content

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?updatest31481855967274]=2&updatest31449688637482]=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?updatesa31481855967274]=2&updatesa31449688637482]=1

 

Any ideas? Thank you kindly :)

@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.


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


Happy to help! Enjoy!