[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Regular Expression Question (easy)

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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

650 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