Search/replace is deleting all lines after the selected line when using regex?
-
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
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.
-
@Rage
.*
is greedy and sucks up as much as it can. Use.*?
to tell the regex parser to perform a non-greedy scan. -
@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. -
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.