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(
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
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:
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
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
Check out the built-in string.startswith() method.
--
http://mail.python.org/mailman/listinfo/python-list