Loading
Help

Find text with regular expressions in Zaps

Last updated:

If you need to separate part of the content from a field, you can do it by using the Formatter's
Extract Pattern transform. This allows you to use regular expressions (regex) to extract partial data from a field.

Note

Regular expression is an advanced feature. Zapier doesn't offer email support for regular expression. If you encounter a problem, we recommend asking questions on Zapier Community or StackOverflow and tagging them with "Zapier".


1. Add a Formatter step to your Zap

  • Click the Action step, or click the plus + icon to add a step to your Zap.
  • Select Format.
  • Click the Action Event dropdown menu and select Text.
  • Click Continue.

2. Set up the “Extract pattern” transform

  • In the Transform dropdown menu, select Extract pattern.
  • Select the field you want to search through in the input field.
  • Enter the Python regex you want to use in the Pattern field.
  • Click Continue.
Note

The Input field can work with line items. It will look for the pattern in each item individually. However, this Formatter step won’t work with line items if the option Match All dropdown is set as Yes.

Tip

3. Optional: Set up option (flag)

To refine your pattern match, select yes from the following dropdown options:
- Match All - Matches all occurrences of pattern. Returns results as line items. Note: If this option is set to Yes, the Input field won't work with line items.
- IGNORECASE - Ignore upper/lowercase differences for matching.
- DOTALL - Allow dot (.) to match newline normally it matches anything but newline.
- MULTILINE - Within a string made of many lines, allow ^ and $ to match the start and end of each line.


4. Optional: Create a group label (Match All only)

When setting the option Match All to Yes, we recommend creating group label in your pattern. This creates named properties in a line item, making it identifiable for use in your Zap later.

Example

In this example, we want to create a group label called all_foo_bars, by using the pattern (?P<all_foo_bars>f[o]+ bar).
Example regex of creating a group label
Example of group labels appearing in the test step


5. Test your step

  • Click Test & Review.

The step will show the results of the regular expression. If the regular expression finds a match, it will return it in the field output. As you can have multiple matches in your pattern, your output can vary. Each match will always return at least these fields:

0 - text of match
_end - last position of match in text
_start - first position of match in the text
_matched - true or false based on the match

Note

If you have multiple matches in your pattern, the first match will appear as 0, second match as 1 etc.

Note

If you're using the option Match All, your results will be returned as line items.

Once you've set up this step, you can add another action where the result of the Formatter step will be used.


Need More Help?

Contact Support

Tell us about your problem, and we’ll find you a solution or you can email support.
Get Help

Hire an Expert

We have a directory of professionals across the globe who are ready to help.
Find a Zapier Expert

Zapier Community

Connect with other Zapier users and industry professionals to get help crafting the perfect workflow.
Check out the community

Zapier University

Video courses designed to help you become a better Zapier user, whether you’re a beginner or more experienced.
View courses