I'm trying to find and replace specific text in a file. And replace it only after a certain match first, because There is no need to change the same text in other places.
<component class="npc" macro="character_argon_male_afr_pilot_01_macro" connection="parentconnection" name="Элан Сламер" code="PRD-472" owner="player" known="1" read="0" page="10105" lastspeaktime="50747.875" id="[0x607c686]">
<listeners>
<listener listener="[0x4165ad0]" event="killed"/>
</listeners>
<movement class="crossconnection">
<additionaloffset/>
<attached component="[0x4165ad0]" connection="con_control01"/>
<time start="50801.319"/>
<offset>
<position x="-0.006" y="-24.275" z="32.788"/>
</offset>
</movement>
<offset>
<position x="0.0164" y="-1.282" z="0.3796"/>
</offset>
<render>
<parameter flags="override" owner="[0x607c686]" name="mat_dynamicglow" type="glow">
<persistent start="47413.071" interval="0"/>
</parameter>
</render>
<traits flags="remotecommable">
<skill type="morale" value="5"/>
<skill type="piloting" value="6"/>
</traits>
it is necessary to change the value in the skill lines, but only for a character of the NPC class belonging to the player (owner = player).
and another question is when what is selected. this is a string, how do I specify any character?
I tried to build a regular expression and all I achieved was selecting the desired NPC and the line after it. (.class="npc".owner="player".)(\n.$) but I just can’t get to the required values.
so, the answer to my problem looks like this.
(?'1'<component class="npc".+owner="player".+\n)(?'2'.+\n)*?(?'3'<traits flags.+\n)\K(?'4'<skill.+value="\d{1,2}".+\n)*regex
replace result
thank to draqula for a hint on the idea