Solved

Regular Expression Question (easy)

Posted on 2004-04-13
5
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

749 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