0

I have a couple of issues in Power Automate Desktop using regex (even after confirmation in regex101). In the parsed text below you can see the following information:

500 (Quantidade/Quantity)

9.999,99 (Valor/Value)

IVA (S4) 0,0 % (IVA/Tax)

I.B.A.N. AB11 1111 2222 3333 4444 5555


Pos. Material Nº Quantidade Preço Unidade de Valor
Material medida EUR
_______________________________________________________________________
11 1234567890123 500 KG 1,11 EUR 1 KG 9.999,99
AAAAA AAA 111/11
AA
AAAAA AAAAAA-11AA
_______________________________________________________________________
Total: 9.999,99 
IVA (S4) 0,0 %
AAAAA AAAAAA
AAAAA AAAAAA
AAAAA AAAAAA
AAAAA AAAAAA
AAAAA AAAAAA
AAAAA AAAAAA
AAAAA AAAAAA
TEL.: +11 11 111 11 11 I.B.A.N. AB11 1111 2222 3333 4444 5555 AA AAAAAAAAA AA 11/11/11

the regex I used for Quantidade is this:

(?<=Pos. Material Nº Quantidade Preço Unidade de Valor
Material medida EUR
_______________________________________________________________________\r?\n\d+\s\d+\s)\d+

it gives me the intended result: 500

the regex I used for Valor is this:

(?<=Pos. Material Nº Quantidade Preço Unidade de Valor
Material medida EUR
_______________________________________________________________________\r?\n\d+\s\d+\s\d+\s\w+\s\d,\d+\s\w+\s\d+\s\w+\s)\d+\.\d+,\d+

it gives me the intended result: 9.999,99

however Power Automate can't handle multiple lines and the regex gets displayed in a single line in the data table and therefore doesn't produce any results. this happens for both cases above:

enter image description here

Question: Can you help me edit these regex so that they are shorter and readable in a single line?

the regex I used for IVA is this:

(?<=IVA\s\(\w+\)\s)\d+\,\d+\s\%

it gives me the intended result: 0,0 % however in Power Automate this regex gets automatically altered into this:

enter image description here

and doesn't produce any result. I've altered it and it continues to revert into that despite any alterations that I make.

Question: Can you help me edit this regex so that I get the intended result?

this is the regex I used to get the IBAN:

(?<=I\.B\.A\.N\.\s)(\w{2}\d{2}\s\d{4}\s\d{4}\s\d{4}\s\d{4}\s\d{4})

it works and gets me the intended result, my question is related to the actual expression. is there a better way to deal with the repetition? I'm referring to the 5 x \s\d{4} in the expression

Apologies for the lengthy question and thanks in advance for any assistance.

Castella
  • 3
  • 1
  • 7
  • As you’ve got a successful answer before (https://stackoverflow.com/questions/76340432/independently-select-reference-and-date-using-regex-for-parsing-text/76341363#76341363), you may want check whether you did something differently this time that your regex gets altered after entering. I can confirm regex in “Parse text” and in “Replace text” works with regex as expected. These additional ` \ ` usually mean that the following ` \ ` is to be treated literally (although, there are some apps that would add this character into regex after entering for to internal processing of that regex string) – Anonymous Jun 02 '23 at 08:20
  • And, yes, you can simplify the 5x repetition, too. In regex101 you have further pane areas with further information (e.g. the break down of your regex or the cheat sheet). So, I would recommend you to spend some time there to test and to solve it by yourself (afterall this is not a free code service here ;-) Last but not least, you may want to pay attention to the different “flavors” of regex. I believe the one used in PAD is .NET (regex101 allows you to select the flavor). So feel free to double-check this with your favorite search engine. Good luck! – Anonymous Jun 02 '23 at 08:28
  • One more thing: about the first 2 regex, you may want to check whether it is really necessary to look for the whole string including the header: e.g. there is “Total: ” before the value, and your quantity is just behind the invoice pos. and material no. (2 and 13 digits?) Most likely, your favorite search engine also helps you to find a template regex for extracting the IBAN no. that you can adjust to your case ;-) – Anonymous Jun 02 '23 at 08:43
  • Apologies if it seems that I'm asking for free code service, I've actually gone through my question and I ask is to review my already written code as I couldn't get any further. – Castella Jun 02 '23 at 16:15
  • In regards to my first 2 regex you are, of course, correct and having gone over the text I was able to narrow it down and remove the multiline issue from PowerAutomate. I'd still like to know how to use multiline regex in Powershell (in case it's actually possible) ;-) – Castella Jun 02 '23 at 16:18
  • as for the double \\ I'm aware of how they work as did go through some tutorials and questions. If you look closely at my question you'll notice these are added automatically by Power Automate seem to prevent the regex from working as intended. I've use look ahead and behind and the result is the same. in this particular case \ are added and prevent the regex from working. – Castella Jun 02 '23 at 16:20
  • Apologies for my assumptions about “free code”. 1. Multiline in PowerShell: I am not familiar with PowerShell. According to here it supports multi lines: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.3 … to my understanding PowerShell uses also .NET regex flavor as with PAD and you can use the options m or s to switch between multi line and single line: https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference – Anonymous Jun 02 '23 at 23:32
  • 2. double \\ : my answer from before still stands, as in both functions blocks “Replace text” and “Parse text” where I use regex, PAD works as expected and does not add a second \ to my regex string, e.g. “Parse text” looks like the screenshot in here: https://learn.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/text … please note, in the regex field no need for wrapping it between “ ... “ – Anonymous Jun 02 '23 at 23:46
  • I am not sure why you asked about multi lines. If your meaning is to get all matches (e.g. there are multiple invoice lines) then it does not matter, as all matches for your regex will be extracted into a list. (In “Parse text” you can choose to get the first match only instead of all) – Anonymous Jun 02 '23 at 23:50

0 Answers0