Negative logic

Questions about XML that are not covered by the other forums should go here.
frogman7
Posts: 3
Joined: Fri Oct 29, 2021 11:31 pm

Negative logic

Post by frogman7 »

I want to find text but exclude in the find certain text:

<tag>1234567890qwerty1234567890</tag>
<tag>1234567890qwerty1111117890</tag>
<tag>1234567890qwerty1234567890</tag>
<tag>1234567890qwerty1234567890</tag>


In my find I want to search for <tag>[^<>]+ NOT 111111</tag>

so my search only finds lines 1, 3, and 4.

Is there a way to do this?
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Negative logic

Post by adrian »

Hello,

I'm guessing you actually mean <tag>[^<>]+ NOT 1111117890</tag>
In that case it works with a regular expression like this (zero-width negative look-behind):
<tag>[^<>]+(?<!1111117890)</tag>

If you have wildcards on both sides of the negated string, it won't work.
e.g.
<tag>[^<>]+(?<!111111)[^<>]+</tag>
This may seem ok in theory, but it's not working in practice.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply