Skip to main content

Regex in Power Automate Desktop: A Practical Guide to Capturing Text

 

Regex in Power Automate Desktop: A Practical Guide to Capturing Text

Regular Expressions, commonly known as Regex, are extremely useful when working with text in Power Automate Desktop (PAD). They allow you to find, identify, and extract specific information from unstructured text such as PDF documents, invoices, bank statements, emails, reports, and forms.

In this guide, we will cover the most commonly used Regex patterns for Power Automate Desktop, with practical examples that can be directly applied to automation projects.

http://regexstorm.net/tester

What is Regex?

A Regular Expression is a pattern used to search for specific text or values within a larger block of text.

For example, suppose a PDF contains:

Customer ID: XXXXX1234
Account No: 99991XXXXX10099
PAN: 12XXXXXXXK

Instead of manually searching for these values, Regex can automatically identify and extract them.

For example:

Customer\s+ID\s*:\s*(\S+)

returns:

XXXXX1234

Similarly:

Account\s+No\.?\s*:\s*([A-Za-z0-9]+)

returns:

99991XXXXX10099

Why Regex is Useful in Power Automate Desktop

When PAD extracts text from a PDF, the resulting text may not have exactly the same formatting as the original document.

For example, the PDF may visually display:

Account No.    Branch       IFSC Code
99991XXXXX10099 KUKATPALLY  IFSC000099

PAD might extract it as:

Account    No. Branch IFSC    Code
99991XXXXX10099 KUKATPALLY IFSC000099

There may be:

  • Multiple spaces

  • Tabs

  • Line breaks

  • Unexpected formatting

  • Text spread across multiple lines

Regex allows us to create patterns that are flexible enough to handle these differences.


1. Basic Regex Characters

These are the fundamental Regex characters you should understand.

RegexMeaningExample
.Any single characterA, 1, @
\dAny digit5
\DAny non-digitA
\wLetter, number, or _Account_1
\WNon-word character@, -
\sWhitespaceSpace, tab, newline
\SNon-whitespaceAccount

2. Matching Numbers

The \d pattern is commonly used when extracting numbers.

One digit

\d

Matches:

5

One or more digits

\d+

Matches:

123456

Exactly 10 digits

\d{10}

Matches:

9876543210

Between 6 and 10 digits

\d{6,10}

Matches numbers containing between 6 and 10 digits.


3. Matching Letters and Numbers

Use character classes when you know what characters are allowed.

Uppercase letters

[A-Z]

Lowercase letters

[a-z]

Any English letter

[A-Za-z]

Letters or numbers

[A-Za-z0-9]

One or more letters or numbers

[A-Za-z0-9]+

This is particularly useful for values such as:

99991XXXXX10099
12XXXXXXXK
ABC123456

4. Understanding \s+

One of the most useful Regex patterns for PDF automation is:

\s+

It means:

One or more whitespace characters.

Whitespace can include:

  • Spaces

  • Tabs

  • New lines

This is important because PDF extraction may convert visual spacing into tabs or multiple spaces.

For example, all of these can potentially be handled:

Account No.
Account    No.
Account        No.

Therefore, instead of:

Account No

it is usually better to use:

Account\s+No

when processing extracted PDF text.


5. Optional Characters Using ?

The ? quantifier means that the preceding element is optional.

For example:

No\.?

can match:

No

and:

No.

This is useful when document formatting varies.

Another common example:

https?://

matches both:

http://

and:

https://

6. Quantifiers

Quantifiers control how many times a pattern can occur.

RegexMeaning
*Zero or more
+One or more
?Zero or one
{3}Exactly 3
{3,}3 or more
{3,10}Between 3 and 10

Examples

\d*

Zero or more digits.

\d+

One or more digits.

\d{6}

Exactly six digits.

\d{6,10}

Between six and ten digits.


7. Capture Groups

Capture groups are one of the most important concepts when extracting values.

Create a capture group by placing the desired pattern inside parentheses:

(...)

For example:

Account No. 99991XXXXX10099

Use:

Account\s+No\.\s+([A-Za-z0-9]+)

The entire match may be:

Account No. 99991XXXXX10099

But the value inside the capture group:

([A-Za-z0-9]+)

is:

99991XXXXX10099

This is exactly what we normally want in an automation.


8. Multiple Capture Groups

You can create multiple groups in the same expression.

For example:

Customer Name: Ramesh Beerla
Account No: 99991XXXXX10099

Regex:

Customer\s+Name:\s*(.+)\r?\nAccount\s+No\.?\s*:?\s*([A-Za-z0-9]+)

Group 1:

Ramesh Beerla

Group 2:

99991XXXXX10099

This allows a single Regex pattern to extract multiple related values.


9. Capturing Text After a Label

This is one of the most common Regex requirements in PAD.

Suppose the document contains:

Customer ID: XXXXX1234

Use:

Customer\s+ID\s*:\s*(\S+)

Result:

XXXXX1234

For:

PAN: 12XXXXXXXK

use:

PAN\s*:\s*(\S+)

Result:

12XXXXXXXK

10. Capturing Text Until the End of the Line

Use:

(.+)

For example:

Customer Name: Ramesh Beerla

Regex:

Customer\s+Name:\s*(.+)

The captured value is:

Ramesh Beerla

This is useful when the value can contain spaces.

For example, \S+ would capture only the first word:

Ramesh

while:

(.+)

can capture:

Ramesh Beerla

11. Capturing a Single Value

When the value doesn't contain spaces, use:

(\S+)

For example:

PAN: 12XXXXXXXK

Regex:

PAN:\s*(\S+)

Result:

12XXXXXXXK

This is often simpler than using [A-Za-z0-9]+.


12. Matching Anything Using .

The dot:

.

matches almost any single character.

For example:

A.B

can match:

A1B
A-B
A B

because the middle character can be different.


13. .* and .*?

These patterns are very useful when working with PDFs.

.*

.*

means:

Match zero or more characters.

It is greedy, meaning it tries to match as much as possible.

.*?

.*?

is non-greedy, meaning it tries to match as little as possible.

For document extraction, .*? is often safer.

For example:

Account.*?Balance

finds the shortest section between:

Account

and:

Balance

14. Matching a New Line

PDF extraction frequently involves line breaks.

Use:

\n

for a new line.

For Windows-style line breaks, use:

\r\n

A flexible option is:

\r?\n

This handles both common formats.

For example:

Account No. Branch
99991XXXXX10099

can be captured using:

Account\s+No\.\s+Branch.*?\r?\n([A-Za-z0-9]+)

The capture group returns:

99991XXXXX10099

15. Matching Anything Except a Character

Use the ^ inside a character class.

For example:

[^,]+

means:

Match one or more characters that are not commas.

For:

Ramesh, Hyderabad, India

this can capture:

Ramesh

Similarly:

[^:]+

captures everything before a colon.


16. OR Conditions

Use:

|

to represent OR.

For example:

Account|Customer|Client

matches any of:

Account
Customer
Client

You can combine this with groups:

Account\s+(No\.|Number)

This can match:

Account No.

or:

Account Number

17. Word Boundary

Use:

\b

to specify a word boundary.

For example:

\bAccount\b

will match:

Account

but not necessarily:

AccountNumber

Another example:

\b\d{6}\b

can be used to find a standalone six-digit number.


18. Extracting Text Between Two Values

Suppose the PDF contains:

Account No. 99991XXXXX10099 for the period

Use:

Account\s+No\.\s+(.+?)\s+for

The capture group returns:

99991XXXXX10099

The ? makes the match non-greedy so it stops at the first occurrence of for.


19. Common Patterns for PDF Automation

Here are some practical patterns you can reuse.

Label followed by a value

Label\s*[:\-]?\s*(\S+)

Label followed by text

Label\s*[:\-]?\s*(.+)

Label followed by numbers

Label\s*[:\-]?\s*(\d+)

Value on the next line

Label.*?\r?\n\s*(\S+)

Text between two labels

Label1\s*(.*?)\s*Label2

20. Common Business Examples

Account Number

Account\s+(?:No\.|Number)\s*[:\-]?\s*([A-Za-z0-9]+)

Example:

Account No: 99991XXXXX10099

Result:

99991XXXXX10099

Customer ID

Customer\s+ID\s*[:\-]?\s*(\S+)

PAN

PAN\s*[:\-]?\s*([A-Z0-9]+)

Indian PIN Code

\b\d{6}\b

Mobile Number

\b\d{10}\b

Date — DD-MM-YYYY

\b\d{2}-\d{2}-\d{4}\b

Date — DD/MM/YYYY

\b\d{2}/\d{2}/\d{4}\b

Email Address

[\w.+-]+@[\w-]+\.[\w.-]+

URL

https?://\S+

Decimal Amount

\d+(?:\.\d{2})?

Matches:

123
123.45

Indian Currency Format

For an amount such as:

11,62,048.27

use:

\d{1,3}(?:,\d{2,3})*(?:\.\d{2})?

21. A Real Power Automate Desktop Example

Suppose PAD extracts the following from a bank statement:

Customer ID: XXXXX1234
PAN: 12XXXXXXXK

Savings Account(s)
Summary
Account No. Branch IFSC Code MICR Code CRN Balance Type
99991XXXXX10099 KUKATPALLY, HYDERABAD IFSC000099

Statement for Account No. 99991XXXXX10099 for the period

We can extract the Account Number using:

Statement\s+for\s+Account\s+No\.\s+([A-Za-z0-9]+)

The important part is:

([A-Za-z0-9]+)

This is Capture Group 1.

The resulting value is:

99991XXXXX10099

This approach is better than relying on the account number always being on a particular line because PDF extraction can change line breaks and spacing.


22. Recommended Regex Pattern for PAD

For most label/value extraction scenarios, start with this structure:

Label\s*[:\-]?\s*(VALUE)

Replace VALUE depending on what you're capturing.

Numbers

Label\s*[:\-]?\s*(\d+)

Letters and numbers

Label\s*[:\-]?\s*([A-Za-z0-9]+)

A value without spaces

Label\s*[:\-]?\s*(\S+)

Text containing spaces

Label\s*[:\-]?\s*(.+)

This simple pattern can solve a large percentage of text-extraction requirements in Power Automate Desktop.


23. Regex Cheat Sheet

RequirementRegex
One digit\d
Number\d+
Exactly 6 digits\d{6}
Letter[A-Za-z]
Letter/number[A-Za-z0-9]+
Non-space value\S+
Whitespace\s
Multiple spaces/tabs\s+
Optional spaces\s*
Any character.
Any text.*
Minimal text.*?
New line\r?\n
Capture value(VALUE)
ORA|B
Word boundary\b
Anything except comma[^,]+
Start of line^
End of line$
Optional character?

Best Practices for Regex in Power Automate Desktop

1. Don't depend on exact spacing

Avoid:

Account No.

Prefer:

Account\s+No\.

2. Use capture groups

If you need only the value, put it inside:

(...)

3. Use labels whenever possible

Instead of extracting the 43rd line, prefer:

Account\s+No\.\s+([A-Za-z0-9]+)

This makes your automation more resilient when PDF layouts change.

4. Test with the actual extracted PDF text

Don't test Regex only against what the PDF visually looks like. Test it against the actual value stored in the PAD variable after Extract text from PDF.

5. Prefer specific patterns

Instead of:

\d+

which may return many numbers, use:

Account\s+No\.\s+(\d+)

when the account number follows a known label.


Final Takeaway

You don't need to memorize hundreds of Regex patterns.

For Power Automate Desktop, focus on these building blocks:

\s+

Whitespace

\d+

Numbers

\S+

Single non-space value

[A-Za-z0-9]+

Letters and numbers

(.+)

Text including spaces

(.*?)

Minimal text capture

\r?\n

New line

(...)

Capture group

Once you understand these, you can combine them to extract almost any structured value from PDF text.

For example:

Statement\s+for\s+Account\s+No\.\s+([A-Za-z0-9]+)

can extract the account number from:

Statement for Account No. 99991XXXXX10099 for the period...

and return:

99991XXXXX10099

That combination of stable labels + flexible whitespace + capture groups is one of the most useful Regex techniques for Power Automate Desktop automation.

Comments

Popular posts from this blog

Key Limitations of Microsoft Power Automate (as of August 2025)

Microsoft Power Automate is a powerful tool for automating business processes, but like any platform, it comes with a set of limitations. Understanding these constraints is essential to designing efficient, scalable, and compliant workflows—especially as your automation strategy grows in complexity.  Here are the most important limits you need to know:  1. Switch Cases Each Switch action supports a maximum of 25 cases. If you need more, consider using nested Switches or alternate logic like parallel branches or conditionals.  2. Actions per Workflow A single flow can contain up to 500 actions. For complex workflows, you may need to split logic into separate flows or use child flows to stay within this limit.  3. Nesting Depth You can nest actions (e.g., conditionals or loops) up to 8 levels deep. Going beyond this will result in a design error.  4. Variables per Flow Each flow can define up to 250 variables. This includes all variable types (string, inte...

Bulk Import Excel Data to SharePoint List Using PowerShell and PnP

  Managing large datasets in SharePoint can be tricky, especially when you're dealing with Excel files and need to avoid list view threshold issues. In this guide, I’ll walk you through a PowerShell script that efficiently imports data from Excel into a SharePoint Online list using PnP PowerShell — with batching support for performance. Prerequisites Make sure you have the following before running the script: SharePoint Online site URL Excel file with data properly formatted PnP PowerShell module installed ( Install-Module PnP.PowerShell ) Appropriate SharePoint permissions What the Script Does Connects to your SharePoint site Loads and reads an Excel file Converts Excel date values Batches records in groups (to avoid the 5000 item threshold) Adds the items to your SharePoint list or library Logs execution time PowerShell Script $siteUrl = "[Site Collection URL]" Connect-PnPOnline -Url $siteUrl -UseWebLogin # Capture the start time $startTime...

Enable or Disable the Social Bar (Like, Views, Save for later) in SharePoint at tenant level

SharePoint Online provides various social features in modern experience SharePoint sites. One of the features available for SharePoint site pages is the social bar (Like, No. of Comments, Views, Save for later), which is situated at the bottom of site pages. Social bar allows users to engage with page content by liking and saving pages for later reference. Social bar also shows the number of page views and comments on modern site pages. However, organizations may have specific requirements that necessitate enabling or disabling the social bar on SharePoint site pages. Unfortunately, there are no settings available for enabling/disabling social bar using SharePoint user interface. In this blog post, we will explore how to achieve this at SharePoint tenant level using SharePoint Online PowerShell, PnP PowerShell and CLI for Microsoft 365 scripts. Using SharePoint Online PowerShell Use below SharePoint Online PowerShell script to enable or disable the social bar from site pages for all Sh...