Grab rate from text file regEx

Hello,

I have the following text:

Albania 10.00% Ethiopia 20.34% Libya 40.22% El Salvador 60.99%
Argentina 9.00% France 0.89% Luxembourg 42% Serbia 1.50%

I want to use a variable that will store a country name. I then want to retrieve the specific countries rate from the above table.

What regex would I use for that?

Hi @Asanka

Is der any format for the data ??

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

well it was a pdf file and i used read pdf.
Thats what it looks like when you write the text to a file.

I don‚Äôt even need the ‚Äú%‚ÄĚ, I just need the number

Hi @Asanka

Can you share the Screenshot of the PDF Data ??

And can you please provide the output text file by setting the property for Preserve Formatting as True as shown in Below SS. So that format remains preserve as it is.

image

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hey,

I can’t share the output.

Is it not possible to just use a regex to grab it?

Hi @Asanka

Yes it will be possible.
But regex will be applied depending on the patterns and format of the data so i asked if any Screenshot u will provide for just that data then it will be well and gud to provide you the exact regex .

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

it appears exactly like this:

Albania 10.00% Ethiopia 20.34% Libya 40.22% El Salvador 60.99%
Argentina 9.00% France 0.89% Luxembourg 42% Serbia 1.50%

Hi @Asanka

Regex for Country names :-
image

Regex for Rates :-

image

Mark as solution and like it if it helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

2 Likes

Hey,

Yeah I can get all the rates. But how do i get the rate for one specific country? For example, El Slavador.

I wanted to pass the country name as a variable and extract its rate

is it possible to pass a variable into a regex? and use the variable as a constant?

Hi @Asanka

Okies. So do the below thing.

readPDFTextOutputVariable.substring(readPDFTextOutputVariable.IndexOf(‚ÄúCountryName‚ÄĚ)+‚ÄúCountryName‚ÄĚ.Length).split(" ")(1)

Mark as solution and like it if it helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

2 Likes

works,

just made the following changes: added c after " " and .tostring at the end

readPDFTextOutputVariable.substring(readPDFTextOutputVariable.IndexOf(‚ÄúCountryName‚ÄĚ)+‚ÄúCountryName‚ÄĚ.Length).split(" "c)(1).tostring

Thanks a lot

Hi @Asanka

Oohh yaa. Actually i forgot that. SOrry for that. Actually while typing any code here some mistake happens bcz suggestions are not der to identify where we are going wrong so.

Its great that you find my mistake n correted it.

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Hey,

So i’m realizing this is working for countries that are one word. However, its not working for countries like New Zealand or Sri Lanka. Any ideas?

HI @Asanka

What is not working you are saying ??

the regex or the String manipulation ??

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

readPDFTextOutputVariable.substring(readPDFTextOutputVariable.IndexOf(‚ÄúCountryName‚ÄĚ)+‚ÄúCountryName‚ÄĚ.Length).split(" "c)(1).tostring

Will only work with countries that are one word. So it will pull the rate for a country like France. However, it will not pull the rate for a country like Sri Lanka. This is because it is two words.

Hi @Asanka

See its working for me

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

thats weird. I’m passing in the country names as variables. Is this the issue you think?

Hi @Asanka

No Way. It must not be the issue.
Just do one thing. Use Writeline activity and print the country name.
Just see that what else anything extra you are getting der or not.

Also do one thing that while passing the countryVariable within the statement whatever i gave you previously just pass it as below.
Note :- Without using double quotes ‚Äú‚ÄĚ
‚ÄúCountryVariable.ToString.Trim‚ÄĚ

And can u tell me one thing that what error/output u r getting for the Country having 2 words previously ??

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer: