logo
Documents
Last updated: Nov 05, 2024

How to use match, test, and replace regular expressions in Power Automate, Azure Logic Apps, or Power Apps

Customer Support Engineer

Many Power Automate users are longing to use regex in their Power Automate flows. Despite thousands of requests, this feature has still not been added. Suggested workarounds usually involve complex scenarios of developing Azure functions or running Excel scripts.

Still waiting for RegEx in Flow for years. It would such a great improvement and prevent tons of cascades of nodes and functions calls / expressions.
Sebastian C. in Power Automate Ideas, Support for Regex in Flow
Coming up on five years to get this extremely useful and needed feature into the product. We pay extra for Power Automate so we can get some of the features for Azure DevOps that JIRA provides out of the box and we still can't do proper validation of form data!
Perry Hunter in Power Automate Ideas, Support for regex - either in conditions or as an action with capture groups exposed

Now, is there an easier way to use regex in Power Automate without all this hassle? The answer is yes! With Plumsail Documents, you can access regular expression actions quickly and easily, and best of all, this feature is free for all subscribers.

Note: Regex actions are also part of our Plumsail Actions connector, which features advanced SharePoint actions. We'll also briefly look at which product is the best choice for your needs.

We'll look at three examples using match, replace, and test regular expression operations. By the time you finish reading, you'll learn how to extract data from email messages, substitute regex, and test if a specific pattern matches given text.

Tip: Regular expressions can be created and tested using services such as Regex101 or RegExr.

Contents

How to use regex match to extract values from email messages

Suppose we get purchase email notifications and need to extract data from them to add it as new entries to a SharePoint list.

Here's an example of what a notification could look like:

*** Order information ***
Time zone: GMT+00:00
Reference: 4563452
Order number: 1400
Payment method: Visa/MasterCard
Order status: Credit card payment authorized

*** Ordered products ***
Product code: D3F13B23B0
Title: Tires
Price: 150
Quantity: 4

Product code: FD3423DE
Title: Cookies
Price: 30
Quantity: 20

Product code: KFG45GK445
Title: Tools
Price: 50
Quantity: 10

*** Delivery information ***
First name: John
Last name: Doe
Company: Happy Company Ltd
Country: Australia
Phone: 01 2345 6780

We'll use the power of the Regular Expression Match action in Power Automate to extract the data from such an email.

Here's the flow we designed for this scenario:

When a new email arrives → Regular Expression Match → Apply to each → Create item

To automate our flow, we use the Outlook connector's 'When a new email arrives' trigger. You can also set a subject filter so that the trigger will only fire when emails have certain keywords in their subject.

Next, we use the match function to find three specific values: Title, Price, and Quantity. The following regex will extract the values just as needed:

Title: (?<Title>.+|)
Price: (?<Price>.+|)
Quantity: (?<Quantity>\d+)

Tip: You can add inline options like case insensitivity and multiline matching by placing them at the beginning of your regular expression inside brackets with a question mark, such as (?mi). Find more options in this MSDN article.

Once the required data is extracted, we generate new items for each order in a SharePoint list.

Check out this article for more details on the implementation of this scenario.

How to use regex replace to substitute values in a string

For our second case, we'll be using the Regular Expression Replace action in Power Automate to find and replace email addresses with [classified] in a text file.

Here's an overview of our flow:

Manually trigger a flow → Get file content → Regular Expression Replace

In this flow, we retrieve the contents of a .txt file stored in a SharePoint document library, and then use the Regular Expressions Replace action to identify any email addresses in it and replace them with [classified].

Below is the regex that we used:

[a-zA-Z0–9._-]+@[a-zA-Z0–9._-]+\.[a-zA-Z0–9_-]+

How to use regex test to check if text matches a specific pattern

In our last example, we'll use the Regular Expression Test action to check if the given email address is valid.

This is what our flow looks like:

Manually trigger a flow → Initialize variable → Regular Expression Test

We used the following regex in this scenario:

[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+

Use RegEx in Power Automate for free with Plumsail

In Power Automate, you can use regular expression (RegEx) actions for free with both the Plumsail Documents and Plumsail Actions connectors. Choose the connector based on your main goals.

Use Plumsail Documents if you work primarily with documents, enabling you to:

  • Create documents from templates
  • Convert various formats to PDF
  • Process PDFs (split, merge, etc.)

Check all available actions in the Plumsail Documents connector.

Use Plumsail Actions for advanced SharePoint management tools, including:

  • Manage permissions for SharePoint sites, lists, and items
  • Handle documents, list items, and folders
  • Create and manage SharePoint sites and lists

Check all available actions in the Plumsail Actions connector.

The RegEx actions in Plumsail Actions work exactly the same as those in the Documents connector described in this article.

Sign up for Plumsail Documents trial

Get started with powerful document automation tools by signing up for a free trial of Plumsail Documents.

Sign up for Plumsail Actions trial

Explore advanced SharePoint actions and data processing by signing up for a free trial of Plumsail Actions.

If you have any questions, feel free to book a call with our specialists to discuss your options.

Note: The post has been originally published at: