Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Regex to replace second value with first value in XML

    Help wanted · · · – – – · · ·
    2
    3
    509
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ben Humpert
      Ben Humpert last edited by Ben Humpert

      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!

      Scott Sumner 1 Reply Last reply Reply Quote 1
      • Scott Sumner
        Scott Sumner @Ben Humpert last edited by

        @Ben-Humpert

        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"/>

        Ben Humpert 1 Reply Last reply Reply Quote 1
        • Ben Humpert
          Ben Humpert @Scott Sumner last edited by

          @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.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors