Insanity

Fredrik Lundh fredrik at pythonware.com
Sun Jan 23 07:26:32 EST 2005


Tim Daneliuk wrote:

> Thanks - very helpful.  One followup - your re works as advertised.  But
> if I use: r'\[PROMPT:[^]].*\]'  it seems not to.  the '.*' instead of just '*'
> it matches the entire string ...

it's not "just '*'", it's "[^]]*".  it's the "^]" set (anything but ]) that's repeated.

"[^]].*\]" means match a single non-] character, and then match as many
characters as you possibly can, as long as the next character is a ].

"[^]]*\]" means match as many non-] characters as possible, plus a single ].

> which seems counterintutive to me.

then you need to study RE:s a bit more.

(hint: an RE isn't a template, it's a language description, and the RE engine
is designed to answer the question "does this string belong to this language"
(for match) or "is there any substring in this string that belongs to this
language" (for search) as quickly as possible.  things like match locations
etc are side effects).

</F> 






More information about the Python-list mailing list