开发者

Notepad++ regular expression replace with slashes and numbers

I'm facing the following problem. I'm trying to replace several paths from config files. These files contains a list of pathnames (one per line), like this:

\\some_server\a_resource\some_library\latest\name_of_the_library.dll

\\some_server\a_resource\other_library\latest\name_of_other_library.dll

I want to replace every line with this:

\\some_server\a_resource\some_library\2.1\name_of_the_library.dll

\\some_server\a_resource\other_library\2.1\name_of_other_library.dll

So, I use notepad++ to replace that in all files but here is the problem.

开发者_运维技巧

The regular expression I use is this:

\\\\some_server\\a_resource\\(.*)\\latest\\

and I want to replace it with:

\\some_server\a_resource\\1\2.1\

Result:

\\some_server\a_resource\somelibrary.1\name_of_the_library.dll

The problem is that the \2 in the "replace with" string is considered as a match and it is replaced by "" (nothing), because there is no second match.

How can I escape the "\2" so the result is a slash and a 2??

Note: If a put \\2 the results is \


If I understand you correctly, you want this as your "Replace with" string:

\\\\some_server\\a_resource\\\1\\2.1\\

i.e. "...a_resource" + escaped backslash ("\\") + matched string 1 ("\1") + escaped backslash ("\\") + "2.1" + escaped backslash ("\\")

Edit: needed a double-backslash before 'a_resource' and doubled the backslashes at the start.


Same problem, but I always do this in 2 steps:

  • first replace with \\\\some_server\\a_resource\\\1\\something_really_strange\\
  • then replace 'something_really_strange' with '2.1' in normal mode
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜