Regex to extract ddMMyyyy

Hello , please help me I want to very perfect regex to extract date from string in the format ddMMyyyy.

I.e in string “formular20092020copy” I want to extract 20092020 which is always going to be a date string in format ddMMyyyy.

Please I don’t know if its possible to make it smart enough to know 44132020 and 1332020 is not valid going by ddMMyyyy just should in case it sees other numbers in the string

Hi @MasterOfLogic

Below is the working workflow for the same :-
MainPratik.xaml (10.2 KB)
New Text Document.txt (84 Bytes)

In the above workflow i have used the Regex First and then If Statement as shown below :-

image

(CInt(item.ToString.Substring(0,2))>=1 And CInt(item.ToString.Substring(0,2))<=31) And (CInt(item.ToString.Substring(2,2))>=1 And CInt(item.ToString.Substring(2,2))<=12) And (DateTime.Now.Year).Equals(CInt(item.ToString.Substring(4,4)))

This will give you only perfect Dates

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

You should better use TryParseExact Method in DateTime.
TryParseExact Method return true if string could be converted to DateTime.

after matching string by Regex, check the value by tryparseexact method.

Refrence : c# - DateTime.TryParse issue with dates of yyyy-dd-MM format - Stack Overflow

2 Likes

@MasterOfLogic

Check as below

Hope this helps you

Follow Link

Thanks

1 Like