Extract Date out of text

How would you extract date out of this text?

@“Monthly letter: Random text
2024-07-09
collapsed”

Text is varying but date would always be in the format yyyy-MM-dd.

Hi @kaurM

Have you tried this activity?

Thank you!
Unfortunately, My studio version (2022.10.4) doesn’t let me update the UiPath.System.Activities package.

Regex for the value:
grafik

Assign Activity:
strDate =

System.Text.RegularExpressions.Regex.Match(yourStringVar,"\d{4}-\d{2}-\d{2}").Value

Parsing into datetime:

DateTime.ParseExact(strDate,"yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
1 Like

System.Text.RegularExpressions.RegEx.Match(inputString,“\d\d\d\d-\d\d-\d\d”)

image

1 Like

Hi @kaurM

Please try the below syntax:

Input = "Monthly letter: Random text
2024-07-09
collapsed"

Output = System.Text.RegularExpressions.Regex.Match(Input, "\d+\-\d+\-\d+").Value.Trim()

Regards

1 Like

Thank you :slight_smile:
Your solution worked

1 Like

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