"+" does not match?

Frank Stajano fstajano at uk.research.att.com
Fri Jun 30 10:11:57 EDT 2000


On Wed, 28 Jun 2000 21:52:26 +0200, Thomas Thiele
<thiele at muc.das-werk.de> wrote:

>>>> import regex 
>
>>>> s1 = "c++test/"
>>>> s2 = "c++test/Derivetest.c++"
>>>> regex.match(s1,s2)
>-1
>
>but if I substitude the "+" I'll get the correct behaviour.
>
>>>> s1 = "c11test/"
>>>> s2 = "c11test/Derivetest.c++"
>>>> regex.match(s1,s2)
>8
>
>Why? Can anybody explain me that?

Because "+" is a metacharacter in regexps, meaning "1 or more
occurrences of the previous regexp", and as such would need to be
escaped in the pattern.

However I suspect that in your case you might be better off using
string.find() rather than regexp.match(), since from the example you
give you don't seem to actually need regular expressions.



More information about the Python-list mailing list