Hey everyone,
Once again I face the issue where a certain REGEX expression captures the intended output in .NET REGEX Tester but not in UiPath.
I made sure to escape the \r and \n but still nothing.
Here is my link to .NET Regex Tester. The expression should capture 4 groups, witch correspond to departures and arrivals:
Any help would be greatly appreciated.
Thank you.
Srini84
(Srinivas Kadamati)
December 7, 2021, 11:26am
2
@andre.f.pires
Itâs capturing correctly in UiPath, check below
can you tell me what issue you are facing?
Thanks
Hey Srini84, thanks for replying.
Well, my sequence is as follows:
First, Iâm reading the PDF file using Read PDF Text activity, outputting the result to the string output.
Then, assign mc, of MatchCollection type = System.Text.RegularExpressions.Regex.Matches(output,â(?<=O/D\r\n).*?(?=;|\r\n|$)â)
Then, inside a for each Iâm logging each item of mc, witch is empty, implying that nothing is being captured.
Printscreen of sequence:
Thank you.
ppr
(Peter Preuss)
December 7, 2021, 11:36am
4
it looks like e.g. the Line break \n
indicator flag is mixed up with the textual representation and escaped value \\n
. within prototyping in the Regex tester. Same also for the \r
Srini84
(Srinivas Kadamati)
December 7, 2021, 11:46am
5
@andre.f.pires
Check as below
Itâs working, Make sure that the For Each TypeArgument is set to System.Text.RegularExpressions.Match
Hope this will help you
Thanks
Thatâs weird.
When you assign the entire body to a string it does work, but if you obtain the string from Read PDF Text activity it no longer works, I double checked.
Assign the output to variable, and it matches the values intended:
Get the body through the Read PDF Text activity and it doesnât match anything:
What could be wrong?
Srini84
(Srinivas Kadamati)
December 7, 2021, 12:06pm
7
@andre.f.pires
You can compare the string, which is coming from Read PDF text activity and the string which Regex is working
Maybe it will help
Thanks
They are the same.
Iâm getting the PDF string by logging the Read PDF string output to a Log Message activity, witch is this:
FATURA\r\nORIGINAL\r\nNÂș DOC. DATA PĂG.\r\nAv. Infante D. Henrique, 73, 1Âș ZF2E 1/1190007073 30-11-2021 1 / 54\r\n1900-263 Lisboa CLIENTE CONTRIBUINTE\r\nTelefone: 21 10 21 040 111527 PT500297177\r\nTelefax: 21 10 21 029\r\n\r\nVIAGENS ABREU SA-PORTO\r\nPRAĂA DA TRINDADE 142, 4Âș\r\n4000-539 PORTO\r\n\r\nVossa ReferĂȘncia: NOV/2021-PVE Galileo NPC Documento interno : 2210705158\r\nData de Vencimento: 30-12-2021\r\nCondiçÔes de pagamento: A 30 dias da data do documento (Unidade:EUR)\r\nDescrição Quant. Valor UnitĂĄrio Valor LĂquido IVA\r\n\r\n10 Transporte de Passageiros - AvÂŽs 1 58,49 58,49 6%\r\nNÂș Bilh 3729-121577 ; D. Venda 22-11-2021 ; BS LC/RG ; O/D\r\nBraga/Lisboa Oriente ; FS TF 3729/125238\r\n\r\n20 Transporte de Passageiros - AvÂŽs 1 42,08 42,08 6%\r\nNÂș Bilh 3729-121516 ; D. Venda 22-11-2021 ; BS LC/RG ; O/D\r\nLisboa S. ApolĂłnia/Porto CampanhĂŁ ; FS TF 3729/125177\r\n\r\n30 Transporte de Passageiros - AvÂŽs 1 30,09 30,09 6%\r\nNÂș Bilh 3729-121521 ; D. Venda 22-11-2021 ; BS LC/RG ; O/D\r\nPorto CampanhĂŁ/Entrecampos ; FS TF 3729/125182\r\n\r\n40 Transporte de Passageiros - AvÂŽs 1 48,58 48,58 6%\r\nNÂș Bilh 3729-119794 ; D. Venda 29-10-2021 ; BS LC/RG ; O/D\r\nPorto CampanhĂŁ/Lisboa Oriente ; FS TF 3729/123455\r\n\r\n50 Transporte de Passageiros - AvÂŽs 1 42,08 42,08 6%\r\nNÂș Bilh 3729-121517 ; D. Venda 22-11-2021 ; BS LC/RG ; O/D\r\nLisboa S. ApolĂłnia/Porto CampanhĂŁ ; FS TF 3729/125178\r\n\r\nTOTAL A TRANSPORTAR\r\n\r\nTotal LĂquido: 221,32\r\n\r\nKdOk - Processado por programa certificado NÂș 631/AT\r\n\r\nSede: Calçada do Duque, 20 1249-109 LISBOA / Telef: 351.211023000 FAX: 351.211023411\r\nContribuinte NÂș 500498601 / Capital Social: ⏠3 959 489 351,01 / RegistoC.R.C.L. NÂș 109 / Internet http://www.cp.pt
The only difference being when you assign this string directly to a variable, then the REGEX expression works.
I am getting the exact output from uipath as well.
May you please help me with your code.
Srini84
(Srinivas Kadamati)
December 7, 2021, 12:29pm
10
@andre.f.pires
Can you try with this below expression?
(?<=O/D\n).*?(?=;|\n|$)
Hope this may help you
Still not working, then can you share a sample pdf file?
Thanks
Srini84:
(?<=O/D\n).*?(?=;|\n|$)
Hereâs a snippet of the code witch reads the PDF file and applies the REGEX expression.
readPdf.zip (70.9 KB)
Srini84
(Srinivas Kadamati)
December 7, 2021, 12:59pm
12
@andre.f.pires
Try with below expression
(?<=O/D\s+).*?(?=;|\n|$)
This will help you
Thanks
Thank you @Srini84 , youâre a lifesaver.
1 Like
system
(system)
Closed
December 10, 2021, 5:48pm
14
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.