Read file by regex?

I want to read pdf by use reges in number 1-5 as below.


test data.txt (291 Bytes)

Please guide me about it.

1 Like

Hi @fairymemay

You can try using the UiPath.PDF activities. Use the Read PDF Text activity available on this activity pack to get the data into a string.

Now, you can use the Matches activity and build a tegex to match the pattern through the inbuilt regex builder…

Let know if this helps…

@Lahiru.Fernando yes, now I can​ read​ pdf​ and​ get​ to​ data​ completed.
But I don’t know​ how​ to​ write​ regex​ in​ matches.

Hello @fairymemay ,

You might want to check this megapost:
Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more - News / Tutorials - UiPath Community Forum

I hope it helps.

Vasile.

Hi @fairymemay

Hope these steps would help you resolve this

—read the pdf with READ PDF activity and get the output as a string variable named str_output

—now use Matches activity and mention the below expression to get the numbers you were expecting and this can be used even if there are more numbers than mentioned in question
([0-9]+(-|,|.)[0-9])+\d

Cheers

@fairymemay - Assuming that page has more number values than the one provided here…I am anchoring the “No.” for the positive look ahead first…

Regex Pattern : (?<=เลขที่ : )[\d-.,]+

Regex101 Link

For the Total Amount: You can assign it to 4 amount variables using Multiassign activity …

Regex Pattern: (?<=จํานวนเงินรวม\s+)([\d.,]+)\s+([\d.,]+)\s+([\d.,]+)\s+([\d.,]+)

Write Line code: "Amt 1==> " + StrOutput(0).groups(1).ToString + vbcr +"Amt 2==> " + StrOutput(0).groups(2).ToString + vbcr +"Amt 3==> " + StrOutput(0).groups(3).ToString + vbcr +"Amt 4==> " + StrOutput(0).groups(4).ToString

Regex Link

Hope this helps…

2 Likes

@prasath17 What type variable StrOutput ?

@fairymemay - MatchCollection

image

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.