Search code examples
c#regexfile-link

c# change file link path using regex


I have problem with regex!

I want to change the filelink ""file:\\" to "file:\" but with this solution i can't because it kill all my other slashes.

"file:\\mail\attach\2015_02\random file name" This file link is in string variable.

Do you have any idea or other solution? Thx!


Solution

  • If you must use regex

    const string originalPath = @"file:\\mail\attach\2015_02\random file name";
    var newPath = Regex.Replace(originalPath, @"file:\\{2}(.+)", @"file:\$1");
    Console.WriteLine(newPath);
    

    Try this DotNetFiddle