Best answer

Simple Regex (exact string) not finding match

  • 29 January 2022
  • 2 replies

Userlevel 1

I want to remove an exact string, and putting ^ at the beginning and $ at the end matches perfectly in regex101 python for me.

It’s a very long string, but same every time. I’m markdown encoding an email, and want to remove the portion that is the signature before url encoding and sending to a webhook. (Another option would be removing an exact number of characters from the end, but the only thing I can find in Zapier formatting is being able to trim from the beginning...)

Is there something else I need to be doing other than ^ and $ to straight match?

Thank you!


Best answer by SamB 29 March 2022, 12:50

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.

2 replies

Userlevel 7
Badge +14

Hi @SirKief 

Are you able to provide screenshots with how you have your Zap step regex configured and an example of the data you are trying to extract?

Userlevel 7
Badge +11

It’s been a while so @SirKief has likely already solved this, but thought I’d pop in here to give some solutions just in case:

Remove the last part of the text

The following Pattern can be used in a Formatter (Text > Extract Pattern) step to extract text from between two values:

You’d need to replace start-text with the first value it needs to find, and end-text with the last value it should find. As the start of the email may be different you can leave the start-text value blank and set the end-text value to be the start of the text you want to remove. E.g. (?<=)(.*?)(?= Remove)

While this doesn’t technically remove the last part of the text. It would return the first section of text that was found before the “ Remove” section starts, which essentially remove the last part of text (“ Remove this.”) entirely from the output:


Remove last X characters
I’ve not tested whether it’s possible to remove the last X characters from text using the Extract Pattern Formatter transform as well, but I do know that it’s possible using a Run Javascript Code by Zapier action. For example if you wanted to remove the the last 12 characters from some text you could set up a Code step like so:

Here’s the code that you can copy and edit as necessary:

var trimmedText = inputData.fullText;
//remove last 12 characters from the text
trimmedText = trimmedText.substring(0, trimmedText.length - 12);
//output the text minus the last 12 characters that were trimmed
return {trimmedText};

Then you’d end up with the last 12 characters being removed from the text:

You can find out more about the Extract Pattern and Run Javascript actions here: