web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / regex() isn't finding ...
Power Automate
Answered

regex() isn't finding 6 digit number invoice

(2) ShareShare
ReportReport
Posted on by 46
I have Power Automate Desktop v2.48.153 on Windows 10. I'm trying to extract data from a PDF which has many invoices. I need to save each individual invoice as it's own PDF using the invoice number as the file name of the output PDF files. 
 
Here are the relevant steps I do.
 
- Find the line with "Customer name" in it, and get the next line which has the invoice number. 
- Split the line with the invoice number by spaces into a list. 
- Loop through that list to find a 6 digit number which is the invoice number, using the regex() function. This is the part that is not working when I step through the steps and look at the variables. If the invoicenum is found then assign it to the variable InvoiceNum and exit the loop early. 
 
Here's how I search for that invoice number in the line of data which has it: 
 
- If regex(variables(%CurrentItem%), '^\d{6}$') equal to True then 
    - set variable InvoiceNum to CurrentItem and exit loop early. This never gets executed. I've also tried this as my regex by having 0 or more spaces before and after the CurrentItem: regex(variables(%CurrentItem%), '^ *\d{6} *$')
 
Could there be some hidden characters in there that I have to filter out? How would I do that? 
What could I be doing wrong here? 
 
It seems the regex() function isn't working. I'm pretty familiar with regex as well. 
 
Thank you.
I have the same question (0)
  • Suggested answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at
    Power Fx is still in preview and does not have all the Power Fx expressions. I would recommend not using Power Fx enabled flows if you don't need to. 

    But either way if you do use regular flow or power fx enabled flow use Parse text -action where you toggle on "Regular Expression".
    Like so:
  • Suggested answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at
    If you are utilizing Power Fx expressions, be aware that they are still in preview and may not function as expected on many occasions, and also have numerous limitations. Therefore, rather than using Power Fx, consider following the alternative approach outlined below(This is power fx disabled flow):
    Code(Copy and paste the below code into your power automate desktop flow):
    SET CurrentItem TO 453456
    **REGION Check if the Currentitem variable has six digits and show a message box if it does
    Text.ParseText.RegexParse Text: Currentitem TextToFind: $'''\\d{6}''' StartingPosition: 0 IgnoreCase: True OccurrencePositions=> OccurrencePositions Matches=> Matches
    IF Matches.Count > 0 THEN
        Display.ShowMessageDialog.ShowMessage Title: $'''Validation''' Message: $'''The Currentitem variable contains six digits.''' Icon: Display.Icon.Information Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    END
    **ENDREGION
    
     
     
    Thanks,
    Deenu
  • crob Profile Picture
    46 on at
    Thank you. I did not know the functions were in preview. I'm still new to Power Automate. 
     
    My Flow is finding the invoice number (on one test I did) but now I want to exit the loop if the LENGTH(%InvoiceNum%) = 6, and it's not exiting the loop. Even though the invoice number found might be "333444"  the exit loop action is not executing. I don't want to continue the loop if I find exactly 6 digits as there may be more digits which are not the invoice number. 
     
  • Suggested answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at
    You get length like this:
    %InvoiceNum.Length%

    So inside the % signs have the variable and .Length



  • Suggested answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at
     Hi,
     
    Please follow as @eetuRobo suggested, you would be able to compare the string length.
     
    Your flow screenshot:


    Why isn't your code working?
    1. It's because you read the match value and assigned it to invoicenum.
    2. Once you assign the invoice number to the invoicenum variable, it becomes a Number type variable.
    3. In Power Automate Desktop, the Number data type doesn't have a length property.
    4. So, you need to convert the invoicenum variable to a string data type using the "Convert number to text" action.
    5. After that, you will have the length property available for your variable.
     
     
     
     
    Thanks,
    Deenu
     
  • crob Profile Picture
    46 on at
    Here's the section of flow I'm still having problems with. 
     
     
    Sometimes InvoiceNum is blank because there is no match. So Convert Number To Text fails with an error "InvoiceNum is not a number." Since I'm so new to PA I'm not sure how to get past this. I'm just not familiar with all the details of PA yet. 
     
    Could someone give me some guidance? 
  • Suggested answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at
    Have if condition that checks if Match is empty. If it is then Next loop.


    Empty string syntax for PAD is: %''%


    By the way are you sure you need to loop the line that has the Invoice number? Maybe reconsider removing the split and for each loop and just use regex to the line after the Customer name.
    So after you have found the line that would have the Invoice number (one after “Customer name” in it) just use Parse text with regex to that line. Also do not have “First occurrence only” checked so it returns all the matches from that row as an array.



    Then if there are many Matches found then do the split and loop. If there is only one match foun (%Matchers.Count% = 1) Then take the first and only Matches value. If there is no match found then notify that the PDF had no invoice number.

    Like so:



    ​​​​​​​

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard