I have OCR extracted date string due to image quality second slash of date comes as 1,
i.e. date comes as 23/0212014 where 1 before year should be / actually. I have tried to replace 1 with regex but its not working.
DateTime.TryParseExact does not work and code i have tried is:
string mm = "23/0212014";
var rex = new Regex(@"(?:((\d{2}\/\d{2})1(\d{4})))");
mm = rex.Replace(mm, "");
How to convert it to proper date (dd/MM/yyyy)?
 
  
                     
                        
DateTime.TryParseExact works fine for me:
using System;
using System.Globalization;
class Test
{
    static void Main()
    {
        string text = "23/0212014";
        DateTime result;
        if (DateTime.TryParseExact(text, "dd/MM'1'yyyy",
                                   CultureInfo.InvariantCulture,
                                   DateTimeStyles.None, out result))
        {
            Console.WriteLine(result);
        }
        else
        {
            Console.WriteLine("Failed to parse");
        }
    }
}
Output:
23/02/2014 00:00:00
(Once you've parsed it as a DateTime you can reformat it however you want, of course.)
I would definitely try to use this rather than regular expressions.
 
                    See more on this question at Stackoverflow