Regular Expression question
__peter__ at web.de
Thu Oct 25 09:25:08 CEST 2007
> On Oct 25, 8:49 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>> needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+',
> What I want here is a RE that return ONLY the line without the "body"
> Your RE return both.
> I know I could use it but I want to learn how to search something that
> is NOT in the string using RE.
You want a "negative lookahead assertion" then:
>>> import re
>>> s = """Isaac Newton
... Isaac Asimov
... Isaac Singer
>>> re.compile("Isaac (?!Asimov).*").findall(s)
['Isaac Newton', 'Isaac Singer']
More information about the Python-list