Author Details



We are a team of tech enthusiast and this section is where we love to share our experience and our knowledge. We try our best to help you understand technical topics by giving you live instances of how-to’s, guides, tips, FAQ’s and troubleshoots.

If you like it or have questions, do share your feedback in the comments section below.

Regex Regular Expression in Power Automate


Regular expressions are very useful for extracting and replacing information from any text but Power Automate does not support Regex(Regular expressions). This blog will provide information on how to use it in Power Automate.

Third party connectors exist which can perform Regular Expressions on behalf of Power Automate, but here, we will focus on how to execute regular expression actions for free, within Power Automate.

As we know that JavaScript supports regex and it can be accessed via Office Scripts in Excel Online. It is possible to pass parameters into, and out of Office Scripts. So, Excel Online can be used as a host for getting access to JavaScript functionality.

Power Automate Regex (Regular expression) Example

Let’s start

I want to extract some string from the email subject followed by some specific word.


1. Create a new automated flow with the following action to get the emails.

Create a new automated flow with the following action to get the emails - Evolvous

2. Add new action “Run script”.

  • I have placed my excel file which contains the office script in OneDrive, so I have selected the OneDrive option. But you can also store this file on any SharePoint site and use it. I will explain the office script later.
  • Below is the regex to match any number or text after the word “Account No:” from the email subject.

Regex regular expression in Power Automate - Evolvous

“Regex Match” script accepts three parameters:

  • The string to perform the regex match on.
  • The regex pattern to use.
  • The flags to pass to the regex object.

3. Create Office Script

a. Create a blank excel file in one drive and open it. You can see Automate menu as shown in the below picture.

Regrex in power automate Create Office Script - Evolvous

By selecting All Scripts, one can see all the scripts. To create a new one click on New Script option.

Below is the script for the Regex match. Create a new script using it and save the file. Then run the flow and check the result.

function main


workbook: ExcelScript.Workbook, inputString: string, pattern: string, flags: string

): Array<string> {

let regExp = new RegExp(pattern, flags);

let matches: Array<string> = inputString.match(regExp);

if (matches) {

return matches;

} else {

return [];



One can use any word in regex as a matching word as per the requirement or can also use the new regex pattern to fulfill the need.

Regular Expression Substitute

Let’s take an example that would be difficult to achieve with standard Power Automate actions. The string has too many space characters, and I’d like to replace them with a single space.

it is very simple with the regular expression pattern ss+:

To substitute text with another text below is the office script:

function main

(workbook: ExcelScript.Workbook,

regexPattern: string,

regexFlags: string,

searchString?: string,

replaceString?: string,

): string {

if(typeof (searchString) === 'undefined' || searchString == "" || searchString == null)

return ""

if (typeof (replaceString) === 'undefined') { replaceString = ''; }

let re = new RegExp(regexPattern, regexFlags)

return searchString.replace(re, replaceString)


Save it in excel office script and use it in the Power Automate like below and check the result.

I hope you found this blog useful. Regular expressions are a powerful tool for working with text, and Power Automate makes it easy to create regular expressions. We hope this article has been helpful, to learn more contact us today.


Plus read

Download file from Power Apps to local dynamically

Follow us