Need regex to get time from a trsing

Hello all,

i am trying to get time from a string. so need to regex to get the time from it.

input string is : EXPECTED DELIVERY DATE | 3/7/23 AT 8:00 AM - 9:00 AM

need to extract 8:00 AM - 9:00 AM.

so can you please help me on this?

1 Like

Hi @sudha456 ,

Use this below code,

YourStr(String as data type) = System.Text.RegularExpressions.Regex.Match("EXPECTED DELIVERY DATE | 3/7/23 AT 8:00 AM - 9:00 AM","\d{1}\:\d{2}\s+[A-z]{2}\s+\-\s+\d{1}\:\d{2}\s+[A-z]{2}").Value

Hope this might help you :slight_smile:

4 Likes

image

Split(“EXPECTED DELIVERY DATE | 3/7/23 AT 8:00 AM - 9:00 AM”," ").Last()

Hey @sudha456
Assign strDate = System.Text.RegularExpressions.RegEx.Match(StrVariable,“\d{0,}:\d{0,}\s\w{2}\s-\s\d{0,}:\d{0,}\s\w{2}”).ToString
image

Cheers.

3 Likes

Hi @sudha456

How about this regular expression

System.Text.RegularExpressions.Regex.Match(YourString,"\d{1,2}:\d{1,2} (AM|PM)").Tostring

image

2 Likes

Thank you all for your quick response.

Hi @sudha456 ,

Maybe an alternate Regex Expression with specificity :

\d{1,2}\:\d{1,2}\s(AM|PM)\s-\s\d{1,2}\:\d{1,2}\s(AM|PM)

Expression :

System.Text.RegularExpressions.Regex.Match("EXPECTED DELIVERY DATE | 3/7/23 AT 8:00 AM - 9:00 AM","\d{1,2}\:\d{1,2}\s(AM|PM)\s-\s\d{1,2}\:\d{1,2}\s(AM|PM)",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value.Tostring

Hi @sudha456 Try the below expression

System.Text.RegularExpressions.Regex.Match(Input,"\d:\d+\s+[A-Z]{1,2}\s+-\s+\d:\d+\s+[A-Z]{1,2}").ToString

Refer the below workflow

Test.zip (2.1 KB)

Capture1

Hello All,
thanks a lot for your quick responses.
facing issue when inout string changes a bit. given regex is unable to get us the time.

input string formats are :
1.ON 3/6/23 AT 10:23 AM - 10:36 AM
2.EXPECTED DELIVERY DATE | 3/7/23 AT 8:00 AM - 9:00 AM

may i have regex which give us the time please?
expected time is 8:00 AM - 9:00 AM

@sudha456 Try the below one it is working for both the cases

System.Text.RegularExpressions.Regex.Match(Input,"\d+:\d+\s+[A-Z]{1,2}\s+-\s+\d+:\d+\s+[A-Z]{1,2}").ToString



@sudha456 This will work for you
YourStrVar = System.Text.RegularExpressions.Regex.Match(InputString,“\d{0,}:\d{0,}\s\w{2}\s-\s\d{0,}:\d{0,}\s\w{2}”).Value

1 Like

Hi @sudha456, here is the regex,

(?<=AT\s)\d{1,2}:\d{2}\s[AP]M\s-\s\d{1,2}:\d{2}\s[AP]M

Thanks a lot for you time and response. it worked .

1 Like

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