How do i extract the second date in the pdf using uipath

In my PDF, I have 2 dates. How do I get the second date? Currently I am using regex expression (Regex.Match(All_Text, “(\d{2}(/)\d{1,2}(/)\d{2,4})”).Value) however this only allows me to extract the first date.

In some scenarios, there is only one date in the pdf. So the expression must be able to get the date as well.

thank you

Hi,

Can you try Matches activity or System.Text.RegularExpressions.Regex.Matches method?

This returns MatchCollection or IEnumerbale<Match> and 2nd item is what you expect.

Regards,

@anonymous3 - Could you please share some sample data with One date and two dates??

Could you elaborate more?

image
image

Hi,

Hope the following helps you.

img20210806-4

mc = System.Text.RegularExpressions.Regex.Matches(All_Text, "(\d{2}(/)\d{1,2}(/)\d{2,4})")

note: mc is MatchCollection type.

Regards,

I have tried, if there is only one date, mc(1).value will have an error

Hi,

mc.Count returns number of items. So we can check if 2nd one exists in advance, as the following.

img20210806-5

Regards,

ok thank you very much

I’ll help you if you promise not to hack me, Anonymous… I’m just kidding!

Lets Go!

First we will use this text example:

Get “Matches” acitivity from activities panel!
image

Look at the properties!

In Input Field we will pass our text containing the dates!
In pattern we can use yours! But i suggest better regex patterns to dates extraction!
image

In the Result Field just press CTRL+K to create an Enumerable variable of matches!

Now you can get your second ocurrence of date at the position 1 !! Look at that!!
image

And the Output is…
image

Our second date ocurrence!!

Hope this helps!