user2645830
user2645830

Reputation: 362

Regex pattern for any string in between

I want to replace strings like

Dependencies\myfolder\1\2\abc.dll
Dependencies\myfolder\abc.dll
Dependencies\myfolder\1\abc.dll

with

packages\abc.dll.

What is the suitable regex pattern to do this. I was expecting the pattern to be -

Dependencies*abc.dll

So my code is -

 var newEntry = packages\abc.dll;
 var pattern = Dependencies*abc.dll;
 var allText = ""; //this contains the text read from a file
 Regex rgx = new Regex(pattern);
 rgx.Replace(allText, newEntry);

But this seems to be a wrong regex pattern.

Upvotes: 1

Views: 59

Answers (1)

Dalorzo
Dalorzo

Reputation: 20024

Almost there you need the .* like:

Dependencies(.*)abc.dll

Online Demo

.NET Online Demo

Upvotes: 3

Related Questions