Checking if string starts with list element

Simon Brunning SBrunning at trisystems.co.uk
Mon Aug 14 12:12:08 EDT 2000


> Subject:	Re: Checking if string starts with list element
> 
> 
> > I want to know whether my sting *starts with* one of the strings in my
> > list.
> 
> The strings all seem to be words; can you get the first word in the
> target string, and see if that is in the list?
> 
> #Untested
> import re
> first_word = re.match('.*\b', us, word)
> if first_word in romans:
>     # do stuff.
>     pass
> 
Uh, interesting. Yes, I'm looking to match first words. I think that re is
the way to go.

One thing that I didn't mention is that the list is built up front, then not
changed. The matching process will happen several times. I can probably
build and compile a nasty re statement up-front, and use it every time I
need to do the match.

I've not used re's before. (Looks at
<http://www.python.org/doc/howto/regex/regex.html>.) I'll get back to you
when I have a clue!

> > If you are not the intended recipient, any disclosure, copying,
> > distribution, or any action taken or omitted to be taken in reliance
> > on it, is prohibited and may be unlawful.
> 
> Cool, are you going to sue me, now? <wink>
> 
The Python-list *is* the intended recipient, (along with c.l.py). So unless
you are a subscriber to neither, and have this message via some form of
hack, you're OK.

Otherwise, watch out! ;)

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list