1

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!

Zoltan
  • 63
  • 8

2 Answers2

6

no need for regex:

 fileLink = fileLink.Replace(@"file:\\",@"file:\");

and you are done

Florian Schmidinger
  • 4,682
  • 2
  • 16
  • 28
  • @Zoltan No need to say thank you. accepting the answer is thank you enough, but you are welcome. Regex is a ultimate swissknife when it comes to strings. however it's focused on finding patterns in strings. You could fix this with regex too but it would be like killing a fly with a robot, state of the art AI, equipped with laser-targeting system and a flyswat, while all you need is that flyswat =) – Florian Schmidinger Mar 03 '15 at 07:25
0

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

J.Jung
  • 26
  • 4