Приведенный ниже код не может извлечь текст даты и преобразовать его - вот что я пробовал до сих пор:
var inputText = "some words 2012-01-06 13-32-40 some words";
string pattern = "d{4}-d{2}-d{2} d{4}-d{2}-d{2}";
var regex = new Regex(pattern);
Match match = regex.Match(inputText);
// it should find the "2012-01-06 13-32-40" text
DateTime result;
if (match.Success)
{
result = DateTime.Parse(match.Value);
}
Как написать шаблон Regex для извлечения части строки даты и как преобразовать эту строку в DateTime?
Я пытался:
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
result = DateTime.ParseExact(match.Value, "yyyy-MM-dd hh-mm-ss", theCultureInfo);
Спасибо