[Tutor] Re: Regular Expressions - who's not working, them or me?!

Andrei project5 at redrival.net
Thu Nov 20 06:01:34 EST 2003


Barnaby Scott wrote on Thu, 20 Nov 2003 00:42:08 -0800 (PST):

<snip>
> why some REs I wrote are not finding matches. They
> only seem to work at the beginning of the string.

>From the docs:
match( string[, pos[, endpos]]) 
If zero or more characters AT THE BEGINNING OF string match this regular
expression, return a corresponding MatchObject instance.

You should use the search() method instead. Or findall.

<snip>

> But I was expecting:
> 
> Match for ".+":  a bunch of text to look in
> Match for "a":  a
> Match for "[a-z]*":  a
> Match for "b": b
> Match for ".\Z": n
> Match for "o{2}": oo
> Match for ".$": n

Here is the output using search instead of match.

Match for ".+":  a bunch of text to look in
Match for "a":  a
Match for "[a-z]*":  a
Match for "b":  b
Match for ".\Z":  n
Match for "o{2}":  oo
Match for ".$":  n

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.




More information about the Tutor mailing list