Community

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

    Deleting specific string from entire xml file?

    Help wanted · · · – – – · · ·
    3
    4
    1408
    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.
    • Team Caffeine
      Team Caffeine last edited by

      I know it sounds easy enough but its not in my case. I am trying to edit a massive xml file, Im modding the game “7 Days to Die”. Throughout the file there are strings called <entityGroup=“spiderZombie” prob=“xxx”/> but the prob is a different number in each one. Therefore, I cannot simply search and replace. If i did it would still have to have the remainder, and would leave the end parts prob=“xxx”/> all over the place.

      Is there any way, I could replace all of these strings, even though they all have different values within them? It is listed like 600 times in the file, which is why I do not want to manually go through each search result and delete the string. Any help appretiated. ty - team_caffeine

      1 Reply Last reply Reply Quote 0
      • guy038
        guy038 last edited by

        Hello, @team-caffeine,

        This kind of manipulation is very easily performed, with regular expressions. So :

        • Open your XML file in N++

        • Move back to its very beginning, if necessary ( Ctrl + Origin )

        • Open the Replace dialog ( Ctrl + H )

        • Type, in Find what: zone, the regex (?-i)<entityGroup="spiderZombie" prob="\d+"/>

        • Let the Replace with: zone EMPTY

        • Select the Regular expression search mode

        • Click on the Replace All button

        Et voilà !


        Assuming, for instance, the 7 lines original text, below :

        blablablah <entityGroup="spiderZombie" prob="000"/> Other text
        blablablah <entityGroup="spiderZombie" prob="123"/> Other text
        blablablah <entityGroup="superHero" prob="999"/> Other text
        blablablah <entityGroup="spiderZombie" prob="456"/> Other text
        blablablah <entityGroup="total_Destroyer" prob="10"/> Other text
        blablablah <entityGroup="spiderZombie" prob="789"/> Other text
        blablablah <entityGroup="spiderZombie" prob="4589"/> Other text
        

        We would obtain, after global replacement :

        blablablah  Other text
        blablablah  Other text
        blablablah <entityGroup="superHero" prob="999"/> Other text
        blablablah  Other text
        blablablah <entityGroup="total_Destroyer" prob="10"/> Other text
        blablablah  Other text
        blablablah  Other text
        

        Notes :

        • I supposed that search must be sensitive to case. If not, change the modifier (?-i) by (?i)

        • I supposed that the prob number is any integer. If it has to be restricted to three digits, only, change the part \d+ by \d{3}

        • On the contrary, if any string entityGroup is concerned by the suppression, use the regex, below :

        (?-i)<entityGroup="\w+" prob="\d+"/>

        With this regex, any entityGroup name, containing word characters ( letters, digits, or the low line character _ ) would be matched and suppressed, in replacement, along with the prob string. So, it would give the resulting text :

        blablablah  Other text
        blablablah  Other text
        blablablah  Other text
        blablablah  Other text
        blablablah  Other text
        blablablah  Other text
        blablablah  Other text
        

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • Team Caffeine
          Team Caffeine last edited by

          Thank you! Im sure this will work, but I am very inexperienced in coding so I still need a little help. The integer is always in the format “0.000”. I tried searching for what you suggested but it did not find anything, however, I don’t know how to change it to where it would find them in this format. All of the values start with 0, and then have three digits after a decimal. So the 3 numbers after the decimal are the only changing factors.

          1 Reply Last reply Reply Quote 0
          • Jim Dailey
            Jim Dailey last edited by

            @Team-Caffeine

            The last part of Guy’s expression:

            \d+
            

            means 1 or more digits. If you want a digit, a period, and exactly 3 digits, one way is to use this:

            \d\.\d{3}
            

            The first \d is for a single digit. The \. is for a period (the period means any character whatsoever unless it has a \ in front of it). The final \d{3} means exactly 3 digits.

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