I am using notepad++ and I have a number of xml files. For example, let's say the XML file is SomeXML.XML.
Within the file, there will be entries such as: //SERVER-NAME/Graphics/Materials/Downloaded/Fabric Grey.jpg
I wish to find these entries (they all start with \SERVER-NAME and end with jpg or png) and replace them with:
//The path to the SomeXML.XML/Fabric Grey.jpg
It must be doable - but I can't figure it out! H-E-L-P.
-- Part 1: generic replacement --
You could give the following regular expression a try:
//.*/([^/]+\.(jpg|png))
To break it down:
.
matches anything, +
means 1 or more)[^\]
means anything except of slash, +
once again means one or more).\.
escapes the dot, so that is interpreted literally)|
means OR)Then just replace with whatever you like. If you use $1 in the replacement it will be replaced with the filename. So in your example SomeXML.XML/$1
would be replaced with SomeXML.XML/Fabric Grey.jpg
.
-- Part 2: replacing SomeXML.XML with the current filename --
Unfortunately putting in the filename can not be done in the same replace action. It has to be done for each file separately, but a macro can help speed it up. Note that the steps below include recording said macro, so it is vital they are executed exactly as described.
SomeXML.XML
.Not fully automated, but this should already make your life quite a bit easier.