Regex groups and split and combine function in regex

how to remove substring from string in uipath ?
like i have date Your date is: 22-26th March 21
i get date from regex 26th March 21
i need to remove ‘th’ from dates having ‘th’ substring


also i need to use group
(?<=Your date is: \d{0,2}-)(?\d{0,2}\w+\s+\w+\s+\d+)

the result should be 26/03/2021

Please guide

@Sakshi_Jain - duplicate of/cross posting

 Datetime.ParseExact("22-26th March 21".split("-"c)(1).Replace("th",string.Empty),"dd MMMM yy",system.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")



@prasath17 so i am getting the date from pdf through regex , output is the type system.text.regularexpresssions.match
while looping through matched items ,

  1. check if the item has th
  2. then assigning the value to string
    Result_date = Datetime.ParseExact(item.ToString.split("-"c)(1).Replace(“th”,String.Empty),“dd MMMM yy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

getting the error as “Assign: Index was outside the bounds of the array.”

@Sakshi_Jain - please add a write Line to see what is the text going into the datetime.parseexact

Hi @Sakshi_Jain
try this way

assuming that u had stored the input data in input_date

input_date = “Your date is: 2-26th March 21”

then use the below assign activity

output_date=DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(input_date,“(?<=Your date is: \d{0,2}-).*”).Value.ToString.Replace(“th”,“”),“dd MMMM yy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

using writeline for displaying output_date, u can see results like u had expected

Hope it helps you


Nived N
Happy Automation

This is working, but the input can be different

I need to read emails
like i need to
check the email body if there is
“Your date is: 22-26th March 21”
“Your date is: 15-19 Feb 2021”
“Your date is: 25-31st March 21”
“Your date is: 28-02 Apr 21”

take the latest date and get the date in format "dd/mm/yyy"

so i need to check if the match string has (st|nd|rd|th) else not
can I do this in the above LINQ query ?
so everything will be done in a single line of code

@Sakshi_Jain - So in one email you will get only one date format right? or multiple?

if you get only one date, you have to add it to array/list and sort the list to find the latest date and then take the output date to parse it…

Yes I am getting one date only , as a list in matches so it one element in a list
[dd MMM yyyy] format
can I include if condition in the above LINQ for list if there is no abbreviation ?
like when output is [11 May 2021] or [11 May 21] i need 11/05/2021