中间任何字符串的正则表达式模式

时间:2015-10-19 14:18:51

标签: c# .net regex

我想替换像

这样的字符串
Dependencies\myfolder\1\2\abc.dll
Dependencies\myfolder\abc.dll
Dependencies\myfolder\1\abc.dll

packages\abc.dll.

执行此操作的合适正则表达式模式是什么。我期待这个模式是 -

Dependencies*abc.dll

所以我的代码是 -

 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);

但这似乎是一种错误的正则表达式模式。

1 个答案:

答案 0 :(得分:2)

几乎你需要.*喜欢:

Dependencies(.*)abc.dll

Online Demo

<强> .NET Online Demo