Regex, string manupulation

Hi All,

“Total payment of $1 on Tuesday will be credited to Test account on 12/12/22

i want to get date 12/12/22. this date are in different format.
I have list of date format :- {“dd MMMM yyyy”, “dd MMM yyyy”, “d MMMM yyyy”, “d MMM yyyy”,“dd MMM yy”,“d MMM yy”,“dd-MM-yyyy”,“dd/MM/yyyy”,“dd/MM/yy”,“dd-MM-yy”}

Here On is the keyword after that date is present.
but on can be present multiple times

Hi @TUSHAR_DIWASE

You can try with Regex Expression

System.Text.RegularExpressions.Regex.Match(YourString,"\d.{2}\S.{1,8}\d{2}").Tostring

Regards
Gokul

HI @TUSHAR_DIWASE

Split Expression

Split("Total payment of $1 on Tuesday will be credited to Test account on 12/12/22").Last

image

Regards
Gokul


cant it be possible that we can check for “on” keyword and if date is present then only extract date otherwise go for next occurrence of “on”

Yes @TUSHAR_DIWASE

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=on\s)\d.{2}\S.{1,8}\d{2}").Tostring

Regards
Gokul

2 Likes

you can do like (?<=on).*\d.{2}\S.{1,8}\d{2}

1 Like

Hi @TUSHAR_DIWASE ,
I think the below expression will give you the most accurate results which you desire.

System.Text.RegularExpressions.Regex.Match(YourString,“\d{1,}.(\d{1,}|\S{1,}).\d{1,}”).Tostring

image

I hope this helps you!

Thanks & Regards,
Shubham Dutta

1 Like

thanks for the reply. it works as well for me along with above two solution.

thanks . you always help me in tight situation.
can you please be kind and explain me \s)\d.{2}\S.{1,8}\d{2} this

HI @TUSHAR_DIWASE

(?<=on\s)\d.{2}\S.{1,8}\d{2}

\s -> Space

\d.{2} -> It will get the 2 number and the Delimiter

\S.{1,8} -> All character upto 1-8 words
1 Like

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