How do I extract dates in multi formats

I have a test data like :
Inputfile_06/02/2025.pdf
Inputfile_02-06-2025.pdf
Inputfile_02/06/2025.pdf
Where I want to fetch only dates irrespective of it’s date formats.
Please suggest me solution using regex

Hi @Nisha_K21

extractedNum = System.Text.RegularExpressions.Regex.Match(filename, “\d{1,2}[-/_]\d{1,2}[-/_]\d{2,4}(?=.pdf$)”).Value

Check this

To extract dates from your filenames using regex in UiPath, try below pattern:

\d{2}[-/]\d{2}[-/]\d{4}

This pattern matches dates in the formats dd/mm/yyyy, dd-mm-yyyy, and mm/dd/yyyy. Here’s how you can use it in UiPath with the Assign activity:

  1. Create a variable to store the filename, e.g., filename.
  2. Use the Assign activity to extract the date using regex.

Here’s an example of how you can set it up:

  1. Assign Activity:
  • To: filename
  • Value: "Inputfile_06/02/2025.pdf"
  1. Assign Activity:
  • To: dateMatch
  • Value: System.Text.RegularExpressions.Regex.Match(filename, "\d{2}[-/]\d{2}[-/]\d{4}").Value

This will extract the date part from the filename and store it in the dateMatch variable.

when using / or - in Regex classes, we recommend to have it escaped with \

Lazy pattern:

restrictive pattern


Kindly note: we used . as we want to match a dot as char not the the any char (only . in a pattern)

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

@Nisha_K21
you can also use this regex:
(\d{2})[\/\-.](\d{2})[\/\-.](\d{4})

1 Like

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