Sponsored Content
Top Forums Programming Python re.findall inverse Match Post 302965330 by metallica1973 on Wednesday 27th of January 2016 11:49:19 AM
Old 01-27-2016
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
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.

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

This did the trick:
Code:
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
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inverse Video

I am trying to discover the sequence of escape characters that I need to pass ksh in order to turn inverse video on and off. I need this information for two reasons: * I want to include inverse video text in some shell scripts * I wish to highlight a section of an /etc/motd file Thanks for... (2 Replies)
Discussion started by: sam_pointer
2 Replies

2. Shell Programming and Scripting

matrix inverse (awk)

I need to inverse a matrix given in a file. The problem is I'm stuck with writing determinant finding algoritm into code. I found this algoritm about finding determinant of nxn matrix. This is what i need: Matrices and Determinants and here: a11 a12 a13 a21 a22 a23 a31 a32 a33... (0 Replies)
Discussion started by: vesyyr
0 Replies

3. Shell Programming and Scripting

use python or awk to match names 'with error tolerance'

I think this is a very challenging problem I am facing and I have no idea how to deal with it Suppose I have two csv files A.csv Toyota Camry,1998,blue Honda Civic,1999,blue B.csv Toyota Inc. Camry, 2000km Honda Corp Civic,1500km I want to generate C.csv Toyota Camry,1998,blue... (7 Replies)
Discussion started by: grossgermany
7 Replies

4. Shell Programming and Scripting

Inverse of Cut

Hi List, I have a CSV file which I am manipulating. Each time I receive the CSV for processing, there will be extra columns of data. Here's what I want to do; I want to be able to remove specific columns from the CSV data file, but keep the remaining columns, where the remaining columns are... (3 Replies)
Discussion started by: landossa
3 Replies

5. Shell Programming and Scripting

Inverse Grep

Hi, I'm trying to wtite a script which actually print the text which doesn't contain a word , i mean to say. eg:- if a file contains the follwoing data Hello how ru ??? What ru doing ? what is the % of data contained ??? I want to write a script such that it prints the line excluding... (1 Reply)
Discussion started by: nagios
1 Replies

6. Shell Programming and Scripting

sed one Liner inverse range match-help required

cat test.txt a c d e g (2 Replies)
Discussion started by: TomG
2 Replies

7. Shell Programming and Scripting

Python fails to detect String Match Found

Below is my code for comparing string for Exact Match found in python. for word in jdbc_trgt.split(','): global comp comp=word.strip(); print "GloBAL:" + comp fiIn = open('list.txt').readlines() for lines in fiIn: print "line1s:" +... (6 Replies)
Discussion started by: mohtashims
6 Replies

8. Shell Programming and Scripting

Python etree.ElementTree findall function

Hi everyone. I'm trying to learn python as it relates to parsing xml, and I thought I would start by trying to create an easy (or I thought would be easy) function to match on a certain attribute in an xml file and print out it's related attribute. Here's an example to hopeful make sense of... (0 Replies)
Discussion started by: timj123
0 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
DPKG-RECONFIGURE(8)						      Debconf						       DPKG-RECONFIGURE(8)

NAME
dpkg-reconfigure - reconfigure an already installed package SYNOPSIS
dpkg-reconfigure [options] packages DESCRIPTION
dpkg-reconfigure reconfigures packages after they have already been installed. Pass it the names of a package or packages to reconfigure. It will ask configuration questions, much like when the package was first installed. If you just want to see the current configuration of a package, see debconf-show(1) instead. OPTIONS
-ftype, --frontend=type Select the frontend to use. The default frontend can be permanently changed by: dpkg-reconfigure debconf Note that if you normally have debconf set to use the noninteractive frontend, dpkg-reconfigure will use the dialog frontend instead, so you actually get to reconfigure the package. -pvalue, --priority=value Specify the minimum priority of question that will be displayed. dpkg-reconfigure normally shows low priority questions no matter what your default priority is. See debconf(7) for a list. --default-priority Use whatever the default priority of question is, instead of forcing the priority to low. -a, --all Reconfigure all installed packages that use debconf. Warning: this may take a long time. -u, --unseen-only By default, all questions are shown, even if they have already been answered. If this parameter is set though, only questions that have not yet been seen will be asked. --force Force dpkg-reconfigure to reconfigure a package even if the package is in an inconsistent or broken state. Use with caution. --no-reload Prevent dpkg-reconfigure from reloading templates. Use with caution; this will prevent dpkg-reconfigure from repairing broken templates databases. However, it may be useful in constrained environments where rewriting the templates database is expensive. -h, --help Display usage help. SEE ALSO
debconf(7) AUTHOR
Joey Hess <joeyh@debian.org> 2011-06-22 DPKG-RECONFIGURE(8)
All times are GMT -4. The time now is 06:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy