[Tutor] regular expression question

Jens Kubieziel python at kubieziel.de
Sun Aug 31 15:56:56 EDT 2003


On Sun, Aug 31, 2003 at 09:46:26AM +0000, nihilo wrote:
> pat = re.compile('a[^a]*a')
> 
> The problem is that I haven't been able to find out how to exclude the
> word if it is more than one character. [^word] excludes the individual
> letters, not the word as a whole, and I tried grouping with braces and
> parentheses  [^(word)], but these don't work.  I've checked many re
> tutorials, and they all say how to exclude a single character from the
> set of characters inside the brackets, but not how to exclude more than
> 1 character.

AFAIK the only way you can do this, is like:

pat = re.compile('a[^w][^o][^r][^d]')

-- 
Jens Kubieziel                                   http://www.kubieziel.de
Another such victory over the Romans, and we are undone.
		-- Pyrrhus



More information about the Tutor mailing list