Example: Changing Date Formats
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Example: Changing Date Formats 

The following code example uses the Regex.Replace method to replace dates of the form mm/dd/yy with dates of the form dd-mm-yy.


    String MDYToDMY(String input) 
        return Regex.Replace(input, 

Regex Replacement Pattern

This example demonstrates the use of named backreferences within the replacement pattern for Regex.Replace. Here, the replacement expression ${day} inserts the substring captured by the group (?<day>…).

The Regex.Replace function is one of several static functions that enable you to use regular expression operations without creating an explicit regular expression object. This is convenient when you do not want to keep the compiled regular expression.

See Also

© 2016 Microsoft