This article describes a few cases when you can use Regular Expressions actions in Microsoft Power Automate or Azure Logic Apps. We will use regular expression actions from Plumsail Documents connector.
Update: We included regular expression actions to our Plumsail SP connector. Now, it is an addition to this set of advanced SharePoint actions as well.
You will learn how to use all regular expression operations like match, replace and test. After reading this article you will be able to extract values from email messages (order notification), replace values in strings, test if the text matches a specific pattern.
This may be helpful in automating your business processes in Office 365, SharePoint or any other system that is integrated with Microsoft Power Automate.
We would recommend you to use Regex Hero tool to create and test your regular expressions. Then you can put them in Microsoft Flow actions.
Plumsail Documents regular expression actions support inline options to modify the behavior of a regular expression. For example, you can set an option for a regular expression to be case insensitive or match multiple lines. You just put options at the beginning of your regular expression inside brackets with a question mark like this (?mi). This example will allow processing multi-line text with case insensitivity. You can find more available options in this MSDN article.
How to use regex match to extract values from email messages
Let’s suppose you are getting a new email after someone made a purchase and you need to extract information from this email and create a new item in your orders SharePoint list.
Your email might look like this:
*** 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
To achieve this we will be using Regular Expression Match action.
So your flow might look like this:
First, we receive an email in Outlook, you can specify Subject Filter field so this trigger will be working only the ones that have ‘Order’ in their subject.
Then we are using Regular Expression Match action to find three values: Title, Price, and Quantity.
Here is a regex we are using in this flow:
Title: (?<Title>.+|) Price: (?<Price>.+|) Quantity: (?<Quantity>\d+)
In the last step, we are using these values to create an item in Orders SharePoint list.
Please read this article for more information about implementation of this case.
How to use regex replace to replace values in string
The second case will be about finding all emails in a text file and replacing them with [classified] string and we will be using Regular Expressions Replace action:
We are getting the text from the .txt file in our Office 365 SharePoint site and use Regular Expression Replace action to see if there are any email and replace them with [classified] string.
This is a regex that we are using:
How to use regex test to check if text matches specific pattern
In the last but not least example, we want to check if the given email is an actual email address.
In that case, you can use Regular Expression Test action in your flow and it might look like this:
The flow is pretty straightforward: suppose we have a variable and we want to check if the value in it is an actual email address.
Here is a regex we are using in this action:
Now you should have an idea how to work with Regular Expressions using Plumsail Documents connector for Microsoft Power Automate. If you haven’t used it yet, registering an account would be the first step, you can learn about it here. It is quite easy to get started.