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 newlinecheckbox, 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 newlineright 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.
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