How to Find only first match of a Date in a String Using Regex

Dear,

I only need to get the first date of this document, I have a lot of difficulty handling regex, could you help me?

I even managed to find the first date with the expression:
\d{2}/\d{2}/20\d{2}

But I still haven’t found a way to find just the first item.

Attached is the .txt
GRF_062021_Tecon RG.PDF.txt (3.2 KB)

@Israel_Silva - Since you have lot of date values in the file, you can extract everything and then print/use only the first one as shown below…

Hope this helps…

1 Like

Try this Regex - \d{2}/\d{2}/(\d{4}|\d{2}), though your regex will also work for all dates between 2000 to 2100 years. also many times the prefix 0 is not used in Days and Months in dates like - 1/12/2021 or 21/5/2021. In these scenarios you can change the regex to - \d{1,2}/\d{1,2}/20\d{2} or \d{1,2}/\d{1,2}/(\d{4}|\d{2})

Also I have uploaded the Uipath workflow for your understanding. You just need to change the path of your Text file.

If this solves your problem please mark it as solution.

Regex.xaml (4.9 KB)

1 Like

Thank you very much my friend, I’m confused, because the 2 solutions above solved my problem

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