How extract dynamic amount of a string variable

Hello i’m reading a pdf and put it into a variable called pdfText i’m doing this be cause is not reading the specific amount but if i read a table of my pdf i get this

as you may think i need to extract the amount “Arriendo de Televia” if it exits but i dont know how to do this, all this info is in my variable pdfText that is the result of a get Text Activity , i though that maybe with something like this:

pdfText.Contains(“Arriendo de Televía”) = true

but after this how i extract the exactly amount?

You could use Matches activity which is Regex Expression. The easiest pattern that I can think of now is Arriendo de Televia\s\d*.?\d*.

2 Likes

i would use matches (?<=Arriendo de Televia\s).*

readPDFText.xaml (12.6 KB)

Also, here is some online regex testers that you can use to understand regex and make your own:

https://regex101.com/

And a fun one:
https://regexcrossword.com/ :wink:

1 Like

Thanks! @Konrad @quihan both are right, it works but i have two question :smile:

1 ) how can i check if the result of this Matches Activity was success or not ? i’m asking this be cause when this does not exist y get an error

image

2 ) if the amount have more than one dot “.” this still work, eg 1.546.567 in this case what would thw way to aboard this ?

I solved this with: "Arriendo de Televía\s\d.?\d.?\d*" and it works for amounts format x.xxx , xxx.xxx and x.xxx.xxx and xx.xxx.xxx**

:smiley: thanks again!

Hi @naotosx, to avoid that error, we can check the Matches count before accessing the variable by using:

Matches.Count > 0 This is to check whether there are any matches. If there is, do the necessary processing.

2 ) if the amount have more than one dot “.” this still work, eg 1.546.567 in this case what would thw way to aboard this ?

To solve this, if you are sure that there will be a Enter space after your text, you can use:
Arriendo de Televia\s.*

If not, you can use:
Arriendo de Televi\s\d*(.?\d*)*

The differences between this and yours is if in future, you have value more than 2 dots. It will still work.

Hope this helps. :slight_smile:

1 Like

What Quihan said

Updated workflow with the changes:
readPDFText.xaml (17.9 KB)

1 Like

@quihan @Konrad your the best guys ! :smiley: thanks a lot for your help :blush: i solved my problems :smile:

No worries @naotosx, happy automating :slight_smile:

1 Like