Skip to main content
Best answer

Simple Regex (exact string) not finding match

  • January 29, 2022
  • 2 replies
  • 1149 views

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

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:
(?<=start-text)(.*?)(?=end-text)


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)

d69786df14bf876e0574e86d97437c86.png
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:

decd63b6236c60ccfa764c2ac3183a63.png


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:
82430ef57fc8c108232818a12d03408b.png

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:
e2f7897e56df3f11372d8650cd617035.png

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

View original
Did this topic help you find an answer to your question?
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

Troy Tessalone
Forum|alt.badge.img+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?


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7906 replies
  • Answer
  • March 29, 2022

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:
(?<=start-text)(.*?)(?=end-text)


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)

d69786df14bf876e0574e86d97437c86.png
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:

decd63b6236c60ccfa764c2ac3183a63.png


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:
82430ef57fc8c108232818a12d03408b.png

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:
e2f7897e56df3f11372d8650cd617035.png

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