• Login
Community
  • Login

Search/replace is deleting all lines after the selected line when using regex?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 4 Posters 230 Views
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.
  • R
    Rage
    last edited by May 12, 2023, 1:55 PM

    Hi there guys, I’m trying to finish some xml coding using notepad++ but I need to replace some text within 368 lines and cant get it to work without deleting additional xml code lines

    image 1

    image 2

    I have tried searching with:
    <entity name=“animalCopterCorpse” prob=“0.*”/>

    To replace with this:
    <entity name=“animalCopterCorpse” prob=“0.00”/>


    The original line is:

    <append xpath=“/entitygroups/entitygroup[@name=‘feralHordeStageGS4086’]”><entity name=“zombieAquaZed” prob=“0.666”/> <entity name=“animalCopterCorpse” prob=“0.610”/><entity name=“zombieAnesthesia” prob=“0.666”/><entity name=“zombieFireElf” prob=“0.593”/><entity name=“zombieIronMan” prob=“0.600”/> <entity name=“animalBurningPhoenix” prob=“0.593”/><entity name=“animalDiamondPhoenix” prob=“0.593”/><entity name=“animalGhastlyPhoenix” prob=“0.593”/><entity name=“zombieTheFlyingPlague” prob=“0.593”/><entity name=“animalFrostyBall” prob=“0.593”/><entity name=“zombieTranslucent” prob=“0.600”/><entity name=“zombieChroma” prob=“0.577”/><entity name=“zombieMummy” prob=“0.600”/><entity name=“zombieRadRobot” prob=“0.600”/> <entity name=“zombieShockerF” prob=“0.577”/><entity name=“zombieExploder” prob=“0.600”/><entity name=“zombieBlazingMan” prob=“0.593”/><entity name=“zombieShadow” prob=“0.593”/><entity name=“zombieSanguis” prob=“0.666”/><entity name=“zombieSc4recrow” prob=“0.455”/><entity name=“zombieRunningMan” prob=“0.621”/><entity name=“zombieFreeza” prob=“0.577”/><entity name=“zombieFireBoss” prob=“0.358”/><entity name=“zombieGunner” prob=“0.358”/><entity name=“zombieRPG” prob=“0.358”/><entity name=“zombiePredator” prob=“0.395”/><entity name=“zombieAtrocity” prob=“0.375”/><entity name=“zombieArch0n” prob=“0.375”/><entity name=“zombieGe1st” prob=“0.375”/><entity name=“animalKaboomPhoenix” prob=“0.320”/><entity name=“zombieGiant” prob=“0.320”/><entity name=“zombieGiantMutated” prob=“0.300”/></append>

    But after executing the above search/replace the line ends ups being

    <append xpath=“/entitygroups/entitygroup[@name=‘feralHordeStageGS4086’]”><entity name=“zombieAquaZed” prob=“0.666”/> <entity name=“animalCopterCorpse” prob=“0.00”/></append>

    I’m not sure why its deleting so much information but at the same time its editing the line in question correctly.

    M P 2 Replies Last reply May 12, 2023, 2:56 PM Reply Quote 0
    • M
      mkupper @Rage
      last edited by May 12, 2023, 2:56 PM

      @Rage .* is greedy and sucks up as much as it can. Use .*? to tell the regex parser to perform a non-greedy scan.

      1 Reply Last reply Reply Quote 3
      • P
        pbarney @Rage
        last edited by May 12, 2023, 6:27 PM

        @Rage said in Search/replace is deleting all lines after the selected line when using regex?:

        I’m not sure why its deleting so much information

        @mkupper has it right… and here’s a bit more detail:

        RegEx searches in N++ are “greedy” by default, meaning that they’ll continue searching the string until they’ve found the last possible instance of what you’re searching for. In your case, the .* will find everything up until the very last "/>.

        The way to prevent this is to add a ? (the lazy modifier) which will stop the search once it finds the first instance of what you’re searching for. You will get used to constantly typing .*? rather than .* (when searching in Notepad++).

        One thing to be aware of: If you have selected the . matches newline checkbox, the greedy .* will search through your entire file. If you do not have it checked, it will only be greedy to the end of each line that it searches.

        Additional tip: you can enable and disable the . matches newline right from the search box by starting your search with (?s) or (?-s) respectively. It overrides the checkbox, so it won’t matter if it is checked or not.

        1 Reply Last reply Reply Quote 4
        • M
          Mark Olson
          last edited by May 13, 2023, 5:30 AM

          My gut feeling is that you should probably be using an XML parser for this sort of thing. I suspect XSLT could be useful, but since I’ve never used it I can’t say more.

          See the XMLTools plugin . Even though it hasn’t been updated recently, it still seems to work fine.

          1 Reply Last reply Reply Quote 2
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors