Solved

Regular Expression Question (easy)

Posted on 2004-04-13
5
229 Views
Last Modified: 2010-04-16
I am processing a list of filenames and would like to determine which files do not end in ",v" using regular expressions.

Obviously to find which filenames DO end in ",v" I would use ".*,v$".

How do I negate that?
0
Comment
Question by:derekl
5 Comments
 
LVL 2

Accepted Solution

by:
Traltixx earned 25 total points
ID: 10830060
well, you can do an if statement to do:

import re

def findV(word):
     if re.search('.*,v$',word) :
          return "v-ed"
    else
          return "not v-ed"


or something hard like:

re.search('.*,[a-u,w-z],word)
or the longer version
re.search('.*,[abcdefghijklmnopqrstuwxyz],word)

note taking into accoutn that it is not case sensitive...hope this helps



0
 

Assisted Solution

by:DEsterkin
DEsterkin earned 25 total points
ID: 10833235
To get the negation in a single expression:

 for f in files:
   if re.search(".*[^(?:,v)]$", f):
     print f

Hope this helps,

0
 
LVL 2

Expert Comment

by:alain_tesio
ID: 10997259
You don't need a regular expression for this, just test fileName.endswith(",v")
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python tuple index error 4 87
Which Eclipse should I install now, Java, Python? 1 142
Using bootstrap with french text 13 95
Python filter object attributes 2 24
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question