Select an xml code snippet with regex

0

I need some help again with Regex! I need to edit an xml file and insert a sequence of instructions after a given information. But I can not select all the information I need. I need to select the following information:

    <testerconfirmation title="Tester Confirmation " passedbutton="yes" timeoutresult="failed">REQUIREMENT SPECTED
After T_Checkdisplay (5 seconds), the indication OIL CHANGE REQUEST V3 must be activated according to indications characteristics during 5 seconds.

Press YES to continue.</testerconfirmation>

In the case above, I need to select all information that is inside the tag and contains the OIL CHANGE REQUEST V3 information. After finding this information I need to insert some lines of code after the selected information. Here are the lines I want to add:

<capltestfunction title="RUN INSPECTION" name="RunInspection">
<caplparam type="string" name="InspName" />
</capltestfunction>
<capltestfunction title="ADD IMAGE TO REPORT" name="AddInspectionImageToReport" />
<capltestfunction title="CHECK ST_F-4" name="CheckStepResultCamera">
<caplparam type="string" name="StepName">ST_F-4</caplparam>
<caplparam type="float" name="ExpVal">1</caplparam>
<caplparam type="float" name="ToleranceUnits" />
<caplparam type="float" name="TolerancePercent" />
</capltestfunction>
<capltestfunction title="CHECK ICON_F-4" name="CheckStepResultCamera">
<caplparam type="string" name="StepName">ICON_F-4</caplparam>
<caplparam type="float" name="ExpVal">1</caplparam>
<caplparam type="float" name="ToleranceUnits" />
<caplparam type="float" name="TolerancePercent" />
</capltestfunction>
<capltestfunction title="CHECK MESSAGE PB058_1" name="CheckStepResultCameraText">
<caplparam type="string" name="StepName">TM_PB058_1</caplparam>
<caplparam type="string" name="ExpVal">OilChange</caplparam>
<caplparam type="int" name="ContainsExpVal" />
<caplparam type="int" name="TolerateSimilarChars">1</caplparam>
</capltestfunction>
<capltestfunction title="CHECK MESSAGE PB058_2" name="CheckStepResultCameraText">
<caplparam type="string" name="StepName">TM_PB058_2</caplparam>
<caplparam type="string" name="ExpVal">Required</caplparam>
<caplparam type="int" name="ContainsExpVal" />
<caplparam type="int" name="TolerateSimilarChars">1</caplparam>
</capltestfunction>

Then the code looks like this:

<testerconfirmation title="Tester Confirmation " passedbutton="yes" timeoutresult="failed">REQUIREMENT SPECTED
After T_Checkdisplay (5 seconds), the indication OIL CHANGE REQUEST V3 must be activated according to indications characteristics during 5 seconds.
Press YES to continue.</testerconfirmation>

  <capltestfunction title="RUN INSPECTION" name="RunInspection">
    <caplparam type="string" name="InspName" />
  </capltestfunction>
  <capltestfunction title="ADD IMAGE TO REPORT" name="AddInspectionImageToReport" />
  <capltestfunction title="CHECK ST_F-4" name="CheckStepResultCamera">
    <caplparam type="string" name="StepName">ST_F-4</caplparam>
    <caplparam type="float" name="ExpVal">1</caplparam>
    <caplparam type="float" name="ToleranceUnits" />
    <caplparam type="float" name="TolerancePercent" />
  </capltestfunction>
  <capltestfunction title="CHECK ICON_F-4" name="CheckStepResultCamera">
    <caplparam type="string" name="StepName">ICON_F-4</caplparam>
    <caplparam type="float" name="ExpVal">1</caplparam>
    <caplparam type="float" name="ToleranceUnits" />
    <caplparam type="float" name="TolerancePercent" />
  </capltestfunction>
  <capltestfunction title="CHECK MESSAGE PB058_1" name="CheckStepResultCameraText">
    <caplparam type="string" name="StepName">TM_PB058_1</caplparam>
    <caplparam type="string" name="ExpVal">OilChange</caplparam>
    <caplparam type="int" name="ContainsExpVal" />
    <caplparam type="int" name="TolerateSimilarChars">1</caplparam>
  </capltestfunction>
  <capltestfunction title="CHECK MESSAGE PB058_2" name="CheckStepResultCameraText">
    <caplparam type="string" name="StepName">TM_PB058_2</caplparam>
    <caplparam type="string" name="ExpVal">Required</caplparam>
    <caplparam type="int" name="ContainsExpVal" />
    <caplparam type="int" name="TolerateSimilarChars">1</caplparam>
  </capltestfunction>

I'm using Notepad ++, however if you have any solution or experience with some other Sw that makes working with code please leave a comment that will also be welcome! Thank you all!

    
asked by anonymous 20.03.2017 / 13:27

1 answer

0

Try using this

( *<testerconfirmation(.|\n)*?(?=<\/testerconfirmation>)<\/testerconfirmation>)

Well, I'll explain in parts what each part does.

 *<testerconfirmation

This regex captures all space characters that have the sequence <testerconfirmation after them and the sequence <testerconfirmation

(.|\n)*?

This part captures all characters (including the special characters) in a lazy way ( link )

(?=<\/testerconfirmation>)

A positive lookahead for capturing up to the

<\/testerconfirmation>

A part to capture , because the positive lookahead only determines where the capture sequence should stop.

As for adding that code sequence, I suggest you use some pretty simple VS application, how to use the regex to scan the code, catch all the occurrences, and concatenate the text string you've described to each of them.     

01.04.2017 / 15:50