Community
    • Login

    Regex to replace second value with first value in XML

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 977 Views 2 Watching
    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 HumpertB Offline
      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 SumnerS 1 Reply Last reply Reply Quote 1
      • Scott SumnerS Offline
        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 HumpertB 1 Reply Last reply Reply Quote 1
        • Ben HumpertB Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors