LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2016, 09:35 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
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.

Last edited by metallica1973; 01-27-2016 at 09:45 AM.
 
Old 01-27-2016, 10:19 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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?

Last edited by grail; 01-27-2016 at 10:21 AM.
 
1 members found this post helpful.
Old 01-27-2016, 10:45 AM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Simply brilliant, I am feeling really really stupid now
 
Old 01-27-2016, 11:52 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

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

Glad I could help
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] python 2.7 unable to match against string szboardstretcher Programming 5 05-06-2013 05:54 PM
Inverse Match in VIM anoosh.michael Linux - General 1 09-27-2011 02:07 AM
[SOLVED] Regular expression to match URL matches fragments - Python madsovenielsen Programming 4 08-29-2010 09:44 AM
match text over multiple lines Python donnied Programming 5 05-24-2009 09:18 AM
Python scriptutil for patterns that don't match donnied Programming 8 03-05-2009 12:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration