How to extract from a column value in datatable of String

How to extract only DateTime value i.e,2019-03-04 09:26:32 from the below column value in a datatable:

“2019-03-04 09:26:32\r\n\r\n03-04 09:26\r\n\r\n8mo”

@Teenu,

try below one

text = “2019-03-04 09:26:32\r\n\r\n03-04 09:26\r\n\r\n8mo”

requiredDate = System.Text.RegularExpressions.Regex.Match(text, “[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}”).Value

UiPath have two exclusive activities to get data through Regular expression.

  1. Use Is Match activity to check whether the required value exists in your string by setting Input in the property as your column value, pattern as “\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}” and set result as a boolean variable to evaluate the existence of the value. (in the image, its set as bIsMatch)
    This step is required because if you directly try to access the element and object is not instantiated, it will lead to exception)
  2. Use if condition to check the existence of the value
  3. If value exists, use Matches activity to get the value by setting Input as your column value, pattern as “\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}” and set a variable for result. The result will be of type IEnumerable (in image RegexResult)
  4. Retrieve required value by accessing the result as
    RegexResult.Cast(of object).FirstOrDefault().ToString.Trim

Thanks!

1 Like