sudha456
(sudhakar)
February 24, 2023, 8:16pm
1
Hello All,
need regex to extract datetime from a string.
example string is :Private Residence
Delivered 01/24/2023 01:38 PM
Recvd by: BRENT M
Appointment scheduled for 01/24/2023 08:00 AM - 04:00 PM
Charges: View charges here
but need only 01/24/2023 01:38 PM
i am suing C# language for UiPath Studio.
thanks in advance.
sudha456
(sudhakar)
February 24, 2023, 8:21pm
2
few more input string sample
sample 1: Shipment Canceled 02/01/2023
sample 2: Delivered 01/23/2023 01:33 PM
Recvd by: GARCIA
Appointment scheduled for 01/23/2023 01:33 PM
Charges: View charges here
COD Amount:
.
arivu96
(Arivazhagan A)
February 24, 2023, 9:08pm
3
Hi @sudha456 ,
Please use below regex to extract the value
\d{2}\/\d{2}\/\d{4} \d{2}:\d{2} (AM|PM)
To get the date value using below syntax in assign activity
strDate=System.Text.RegularExpressions.Regex.Match(yourString,"\d{2}\/\d{2}\/\d{4} \d{2}:\d{2} (AM|PM)").Value
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
Regards,
Arivu
2 Likes
sudha456
(sudhakar)
February 26, 2023, 7:15am
4
Hello Arivu96,
thanks for the quick response.
I tried the same but it sthrowing an exception.
i am suing C# langague to build the project. it might be working for vb.net but not for C#.
Anil_G
(Anil Gorthi)
February 26, 2023, 7:28am
5
@sudha456
Please use like this
System.Text.RegularExpressions.Regex.Match("",@"\d{2}/\d{2}/\d{4} \d{2}:\d{2} (AM|PM)").Value
Feel free to mark solution if working else happy to help
Hope this helps
cheers
sudha456
(sudhakar)
February 26, 2023, 7:40am
6
Hello Anil,
thanks for quick support.
its working fine when we have AM or PM but returing null when input string does not have those
Anil_G
(Anil Gorthi)
February 26, 2023, 7:43am
7
@sudha456
So according to what we did…it matches the expression only when all of those are present…Else it would be null only…Does some dates dont have AM or PM? if do use the below expression
\d{2}/\d{2}/\d{4} \d{2}:\d{2}
cheers
sudha456
(sudhakar)
February 26, 2023, 7:47am
8
Thanks a lot,
can i get one more regex to get date when input contains only MM/dd/yyyy?
Thanks a lot
Anil_G
(Anil Gorthi)
February 26, 2023, 7:49am
9
Anil_G:
\d{2}/\d{2}/\d{4}
@sudha456
This is for date
\d{2}/\d{2}/\d{4}
You can actually match all of those 4 patternn together using this
\d{2}/\d{2}/\d{4}( \d{2}:\d{2})*( AM| PM)*
Hope this helps
cheers
system
(system)
Closed
March 1, 2023, 8:02am
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.