please help with simple regex
jam
jam at p98.f112.n480.z2.fidonet.org
Thu Jul 1 13:10:34 EDT 1999
More information about the Python-list mailing list
Thu Jul 1 13:10:34 EDT 1999
- Previous message (by thread): Why is no exception raised for file.read() when file is only writeable?
- Next message (by thread): please help with simple regex
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: jam <jam at newimage.com> On Fri, Jul 02, 1999 at 12:35:51AM +0000, viofis at my-deja.com wrote: > > I'm a beginner at Python, so this may be a stupid question: > > I have a string, for example, myString="the Potato". > 1. Convert it to all lowercase ("the potato") > 2. Match it against a list of strings - "potato,tomato,corn,etc...", > extract "potato" (if it matches with something on the list), then save > into myNewString. > > Any help is greatly appreciated. > > thanks, > Vadim > hi. I don't quite understand what it is you are trying to do. if you want to take a string and find out if it contains some other string, you probably don't need to worry about regular expressions at all. what kind of problem are you trying to solve? do you 'need' to use a specific solution for some reason? I tried this: [~] [9:02pm] [jam at toast-pts/6] % python Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import string >>> buf = "The Carrot" >>> validveggies = ("carrot", "corn", "spam") >>> buf = string.lower(buf) >>> for w in string.split(buf): ... if w in validveggies: ... print "valid veggie '%s' found." % (w) ... valid veggie 'carrot' found. does that help? regards, Jeff -- || visit gfd <http://quark.newimage.com/> || psa member #293 <http://www.python.org/> || New Image Systems & Services, Inc. <http://www.newimage.com/>
- Previous message (by thread): Why is no exception raised for file.read() when file is only writeable?
- Next message (by thread): please help with simple regex
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list