Gerald Hughes
Gerald Hughes

Reputation: 6159

C# regex replace in paths

I'm trying to use regex_replace in c#

This are my strings

my\old\path\Win32\my.dll
my\old\path\Win64\mydll2.dll

I'm trying to replace them with

my\new\path\Win32Release\my.dll
my\new\path\Win64Release\mydll2.dll

This is how I do it and doesn't work in c# but works in notepad++

Regex.Replace(test, @"\bmy\\old\\(.*)\\[a-z]+([0-9]{2})\\((.*)+\.[a-z]{3})\b", @"my\\new\\path\\Win\2Release\\\3")

Upvotes: 0

Views: 215

Answers (2)

Eamonn McEvoy
Eamonn McEvoy

Reputation: 8986

replace:

\\Win(..)\\

with:

\\Win($1)Release\\

Upvotes: 1

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

Your pattern doesn't work because you have forgotten to make it case-insensitive. You can add (?i) at the begining of the pattern or use RegexOptions.IgnoreCase

Upvotes: 2

Related Questions