Regex Substitution

Hi,

I need to substitute an extra colon in my date time field to allow it to be parsed by the DateTime.Parse method. I have tried using the substitution constructs ${name} and the $groupnumber but they in turn stop the validation of my regular expression which was working previously. (Testing using Sells Brothers RegexDesigner). Can some one provide a working example of the substitution construct.

Thanks

tribal



Answer this question

Regex Substitution

  • reggio

    Hi Josh,

    Thanks a lot, thats just what i needed. My date time string was as follows

    "03/Sep/2002:09:49:52" (notice the extra colon after the date)

    I used parseexact and it works fine. THe code I used is as follows

    DateTime.ParseExact(alphaNumDate.Match(str).Groups["alphanumdate"].Value, "dd/MMM/yyyy:HH:mm:ss", new DateTimeFormatInfo())

    Regards,

    tribal



  • AdriaanDavel

    Hello Tribal,

    Could you post the value of the date-time field as well as the values for the other arguments being passed to the DateTime.Parse method please

    Also, instead of modifying the date-time string before calling DateTime.Parse, it might be more appropriate to call DateTime.ParseExact instead and pass in a format string.

    Thanks,
    Josh Free
    Base Class Libraries Development


  • Regex Substitution