Re: Testing for the first few letters of a string

2008-08-07 Thread Jean-Paul Calderone
On Thu, 07 Aug 2008 23:08:10 +0200, magloca <[EMAIL PROTECTED]> wrote: John Machin wrote: import re template = '^My name is alex' The ^ is redundant. Didn't the OP want to match only at the beginning of the string? That's why it's "redundant" instead of "incorrect". ;) re.match = match(

Re: Testing for the first few letters of a string

2008-08-07 Thread magloca
John Machin wrote: >> import re >> template = '^My name is alex' > > The ^ is redundant. Didn't the OP want to match only at the beginning of the string? m. -- http://mail.python.org/mailman/listinfo/python-list

Re: Testing for the first few letters of a string

2008-08-07 Thread John Machin
On Aug 8, 1:53 am, [EMAIL PROTECTED] wrote: > use re module Using re.match instead of str.startswith is overkill. > > import re > template = '^My name is alex' The ^ is redundant. > astring = 'My name is alex, and I like pie' > if re.match(template, astring): > print 'Found it' > else:

Re: Testing for the first few letters of a string

2008-08-07 Thread Sean DiZazzo
try string1 = "My name is alex" string2 = "My name is alex, and I like pie" if string2.startswith(string1): process() or if you want to match a set number of characters you can use a slice: if string2[:15] == string1[:15]: process() or if you dont care where the characters appear in

RE: Testing for the first few letters of a string

2008-08-07 Thread Edwin . Madari
use re module import re template = '^My name is alex' astring = 'My name is alex, and I like pie' if re.match(template, astring): print 'Found it' else: print '%s does not begin with %s' % (astring, template) good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EM

Re: Testing for the first few letters of a string

2008-08-07 Thread Shawn Milochik
Check out the built-in string.startswith() method. -- http://mail.python.org/mailman/listinfo/python-list