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
d then later testing to see what n was = to and figuring out if it got > through the whole loop. I feel like there should be an easier way to do > this, and probably is. So Does anyone have a suggestion? > -- > View this message in > context:http://www.nabble.com/Testing-for-the-first-

RE: Testing for the first few letters of a string

2008-08-07 Thread Edwin . Madari
age- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alexnb Sent: Thursday, August 07, 2008 11:40 AM To: python-list@python.org Subject: Testing for the first few letters of a string Okay, I have a fix for this problem, but it is messy and I think there might be a better way. Her

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

Testing for the first few letters of a string

2008-08-07 Thread Alexnb
and figuring out if it got through the whole loop. I feel like there should be an easier way to do this, and probably is. So Does anyone have a suggestion? -- View this message in context: http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-tp18873375p18873375.html Sent from th