re question (perhaps a stupid misunderstanding of regex-logic)

Stefan Antoni sasoft at gmx.de
Tue Jul 30 08:53:03 EDT 2002


i am currently reading Jeffrey E. F. Friedl's book about regex'es, and i
must admit that i play more with the re-module then reading further on
;)

thats why i ask the following question:

i made the following regex:
m  = re.compile("[^M]*")

i think, it would be read as: "find everything except the occurences of
the char 'M' " .
i wrote the following code:

all = string.letters + string.digits + string.hexdigits + \
string.whitespace

M  = re.compile("[^M]*")
M.findall(all)
['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL', '', \
'NOPQRSTUVWXYZ01234567890123456789abcdefABCDEF\t\n\x0b\x0c\r ', '']

this gives me a list with an empty item at [1] of the list.
the documentation says: "findall: Find all occurrences of a
pattern in a string."

since the ^M is a negated char (german "negiert", i don't know if negated is
right), the regex-object shouldn't give me an list-item for this match, or should
it? 

what am i missing?


thx in advance,

-- 

      Stefan Antoni
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20020730/5aa8e7e6/attachment.sig>


More information about the Python-list mailing list