LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python re.findall inverse Match (https://www.linuxquestions.org/questions/programming-9/python-re-findall-inverse-match-4175568032/)

metallica1973 01-27-2016 09:35 AM

Python re.findall inverse Match
 
Python gods, 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
Code:

'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:
Code:

'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:
Code:

'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:
Code:

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.

grail 01-27-2016 10:19 AM

Well I am not a python guru, but why not just change the test? This worked for me:
Code:

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

Let me know if I misinterpreted what you were after?

metallica1973 01-27-2016 10:45 AM

Simply brilliant, I am feeling really really stupid now :)

grail 01-27-2016 11:52 AM

geez, if that is your first time you have a lot of catching up to do :)

Glad I could help


All times are GMT -5. The time now is 03:53 PM.