?
Solved

Regular Expression Question (easy)

Posted on 2004-04-13
5
Medium Priority
?
243 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 100 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 100 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
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 …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

752 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