Python re.findall inverse Match

I ask of you but yet another simplistic question that I hope can be answered. Its better explained showing my code. Here is my list(tmp_pkglist), which contains a list of all Debian (Jessie) packages:
snippet

 'zssh (1.5c.debian.1-3.2+b1 [s390x], 1.5c.debian.1-3.2 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])',
 'zsync (0.6.2-1)',
 'ztex-bmp (20120314-2)',
 'zurl (1.3.1-4)',
 'zutils (1.3-4)',
 'zutils-dbg (1.3-4) utilities for dealing with compressed files transparently (debug)',
 'zvbi (0.2.35-3) Vertical Blanking Interval (VBI)',
 'zygrib (6.2.3-1)',
 'zygrib-maps (6.2.3-1)',
 'zynadd (1+git.20100609+dfsg0-2)',
 'zynaddsubfx (2.4.3-4)',
 'zynaddsubfx-dbg (2.4.3-4)',
 'zynaddsubfx-dssi (2.4.3-4)',
 'zypper (1.11.13-1)',
 'zypper-common (1.11.13-1) command line software manager using libzypp (common files)',
 'zypper-doc (1.11.13-1) command line software manager using libzypp (documentation)',
 'zziplib-bin (0.13.62-3)',
 'zzuf (0.13.svn20100215-4.1+b1 [s390x], 0.13.svn20100215-4.1 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])']

Using this block of code and using re.findall, how can I tell the regex to "not" or inversely find all of the lines that do not contain:

 'zssh (1.5c.debian.1-3.2+b1 [s390x], 1.5c.debian.1-3.2 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])
'zzuf (0.13.svn20100215-4.1+b1 [s390x], 0.13.svn20100215-4.1 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])']

I tried various combos but cannot get the inverse of what I want which is:

 'zypper (1.11.13-1)',
 'zypper-common (1.11.13-1) command line software manager using libzypp (common files)',
 'zypper-doc (1.11.13-1) command line software manager using libzypp (documentation)',
 'zziplib-bin (0.13.62-3)',

For example:

for scrape in tmp_pkglist:
            capture = re.findall('?!(.*\[s390x\].*))', scrape)
            if capture:
                    print capture

I am used to using "!" or boolean "not" but have never done it using Pythons "re" module. Thanks in advance.

---------- Post updated at 11:49 AM ---------- Previous update was at 10:44 AM ----------

This did the trick:

for scrub_norm in tmp_pkglist:
    sanitize_norm = re.findall('.*\[s390x\].*', scrub_norm)
    if not sanitize_norm:
        print scrub_norm

Thanks to grail from antother forum

From the docs at re — Regular expression operations — Python 3.12.0 documentation

Or, if you don't care what langauge is used, just pipe a grep -v like the following:

$ apt-cache search foo | grep -v bar

Yes, Python uses the more verbose "not" instead of "!" for negative regex matches.

$
$ cat pkg_list.txt
'zssh (1.5c.debian.1-3.2+b1 [s390x], 1.5c.debian.1-3.2 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])',
'zsync (0.6.2-1)',
'zzuf (0.13.svn20100215-4.1+b1 [s390x], 0.13.svn20100215-4.1 [amd64, arm64, armel, armhf, i386, mips, mipsel, powerpc, ppc64el])']
'ztex-bmp (20120314-2)',
$
$ cat -n negative_match.py
     1  #!/usr/bin/python
     2  import re
     3  input_file = "pkg_list.txt"
     4  for line in open(input_file):
     5      if not re.match('.*\[s390x\].*', line):
     6          print line,
     7
$
$ python negative_match.py
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$

For reference, here's the corresponding regex in Perl:

$
$ perl -lne 'print if !/\[s390x\]/' pkg_list.txt
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$ perl -lne 'print if not /\[s390x\]/' pkg_list.txt
'zsync (0.6.2-1)',
'ztex-bmp (20120314-2)',
$
$
1 Like