0

I have a well structured XML file with several grouped units, which contain a consistent number of child elements.

I am trying to find a way, through Regex in Notepad++, to search throughout all of these groups for a certain argument that contains a single word. I have found a way of doing this but the problem is I want to find the negation of this word, that means for instance, if the word is "downward" I want to find anything that is NOT "downward".

Here is an example:

<xml:jus id="84" trek="spanned" place="downward">

I've came up with <xml:jus id="\d+" trek="[\w]*" place="\<downward"> to find these tags, but I need to find all other matches that do not have "downward" in place= argument. I tried <xml:jus id="\d+" trek="[\w]*" place="^\<downward"> but without success.

Any help is appreciated.

Pedro Sousa
  • 445
  • 6
  • 12

2 Answers2

2

If the properties and the string is in the same format, you could also make use of SKIP FAIL to first match what you want to exclude.

<xml:jus id="\d+" trek="\w+" place="downward">(*SKIP)(*F)|<xml:jus id="\d+" trek="\w+" place="[^"]+">

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
  • Great, this seems to work flawlessly, thanks. Just one more thing. Lets say that I want to replace everything that is not "downward" by "downward". How would I go about replacing it? – Pedro Sousa Apr 13 '21 at 09:25
  • @PedroSousa In that case you can use `]*>)` https://regex101.com/r/YEgFCC/1 – The fourth bird Apr 13 '21 at 09:36
1

You might be able to use a negative lookahead to exclude downward from being the place:

<[^>]+ place="(?!downward").*?"[^>]*>

Demo

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360