Regex Expression for these formats

Hi,

Need regex expression for both of these.

02/13/2022 and 09:30:00

How to differentiate between them .

Hi @shirin.sebatina

Try this expression to get both the values in single expression

System.Text.RegularExpressions.Regex.Match(InputStr,"\d.{2}\d.{2}\d{2,4}").Tostring

image

Try this expression to get Date values

System.Text.RegularExpressions.Regex.Match(InputStr,"\d.{2}\d.{2}\d{4}").Tostring

Regards
Gokul

Simple pattern with options:
grafik

Advanced with Group Names:
grafik
grafik

So based on the group name we can retrieve which case we got

Hi @shirin.sebatina ,

Here is an interesting take on this subject, but I guess ppr has beaten me to it!

Basically, you have the option of assigning names to “groups” of matches.

Here is one such example →

image

(?<date>\d+\/\d+\/\d+).*?(?<time>\d+\:\d+\:\d+)
System.Text.RegularExpressions.Regex.Matches(str_DateandTime,"(?<date>\d+\/\d+\/\d+).*?(?<time>\d+\:\d+\:\d+)")

And that allows you to do something amazing like this →

image

matches.Item(0)
matches.Item(0).Groups("date")
matches.Item(0).Groups("time")

Really beautiful stuff, I’d recommend you give it a try.

Kind Regards,
Ashwin A.K

For the first format 02/13/2022 you can use below format

For the second format 09:30:00 you can use the below format