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
Yoichi
(Yoichi)
August 6, 2021, 3:08am
2
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?
Yoichi
(Yoichi)
August 6, 2021, 3:16am
6
Hi,
Hope the following helps you.
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
Yoichi
(Yoichi)
August 6, 2021, 3:27am
8
Hi,
mc.Count returns number of items. So we can check if 2nd one exists in advance, as the following.
Regards,
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!
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!
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!!
And the Output is…
Our second date ocurrence!!
Hope this helps!