Select XML if Child values match

Issue: Find the third XML that matches two conditions in Notepad++ with regex

Using a regex in Notepad++, find the third XML in the list that matches two conditions:

<ns:Input>..<ns:locationevent>yyyy</ns:locationevent>..<ns:Action>..<ns:name>def</ns:name>..
<ns:Input>..<ns:Coverage>..<ns:Action>..<ns:name>def</ns:name>..<ns:ID>1423</ns:ID>..</ns:Input>

Instructions:

  • Use the following command in Notepad++ <ns:Input>(?:(?!</ns:Input>).)*<ns:locationevent>yyyy</ns:locationevent.*?<ns:Action>.*?<ns:name>def</ns:name>.*?<ns:Coverage>.*?<ns:Action>.*?<ns:name>def</ns:name>(?:(?!</ns:Input>).)* (1423).*?</ns:Input>
  • Find the third XML that matches the two conditions given above.

Answer: To find the third XML that matches the two conditions given above using the regex command in Notepad++:

  1. Open the file containing the XMLs in Notepad++.
  2. Press Ctrl + F to open the Find window.
  3. Select the Mark tab.
  4. In the Find what field, paste the following command: <ns:Input>(?:(?!</ns:Input>).)*<ns:locationevent>yyyy</ns:locationevent.*?<ns:Action>.*?<ns:name>def</ns:name>.*?<ns:Coverage>.*?<ns:Action>.*?<ns:name>def</ns:name>(?:(?!</ns:Input>).)* (1423).*?</ns:Input>
  5. Make sure that the Regular expression option is selected.
  6. Click on Mark All.
  7. Look at the bottom of the Find window to see how many matches were found.
  8. If there are at least three matches, close the Find window.
  9. Press Ctrl + Shift + F to open the Find in Files window.
  10. In the Find what field, paste the same command as in step 4.
  11. In the Filters field, enter the file type(s) you want to search in.
  12. In the Directory field, enter the path to the folder where the file(s) are located.
  13. Click on Find All.
  14. Look for the third match in the search results.