Regex to replace second value with first value in XML
Hello and sorry for this probably stupid question but I simply can’t understand Regex.
I have hundres of these entries in a file
<file source=“00 Required\Meshes\AnimTextData\AnimationFileData\1015565736507645228.txt” destination=“Materials\Sample\WallLockCleanMetal.bgsm”/>
The first value of variable “source” is different in each line, the value for variable “destination” may be different. I tried to match everything between " and " and replace the second match with the first one. I can match but replacing is a whole different topic.
Using the above example the result sould be
<file source=“00 Required\Meshes\AnimTextData\AnimationFileData\1015565736507645228.txt” destination=“Meshes\AnimTextData\AnimationFileData\1015565736507645228.txt”/>
My Regex so far is (?<=").*?(?=") but that is surely not complete since it also matches " destination=" (without “”).
Any help is highly appreciated!
Not quite sure I understand the implications of the
00 Required\part of the source, but this simple replacement may be of some use:
Find what zone:
<file source="00 Required\\(.+?)" destination=".+?"/>
Replace with zone:
<file source="00 Required\\\1" destination="\1"/>
@Scott-Sumner That works perfectly. Thank you very much! I now see how wrong I was with my approach ;)
00 Required\is the directory the files are stored in(side the zip file) but after extraction / installation they don’t need to be in
00 Required\since this is just for keeping the zip archive clean.