
Hallo, ich bin neu hier und hoffe, dass ich zum Einen mit dieser Anfrage keinen Fehler gemacht habe und zum Anderen, dass mir jemand bei meinem Problem helfen kann:
Ich möchte in einer Regular Expression das "negative lookbehind" einsetzen - habe es aber auch nach stundenlangem Versuchen nicht hinbekommen.
Hier der Auszug aus der Python Help:
(?<!...)
Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning of the string being searched.
Und hier mein Testprogramm:
import re line_s = ['#begin-a AND End-a 2', '!begin-b and End-b 3'] regexp = r'begin(!AND)' c_regex = re.compile(regexp) for x in line_s: print '-' * 20, x if c_regex.search(x) != None: print 'found it...' else: print "didn't find it..."
Ich erwarte, dass einmal der if- und einmal der else-Zweig durchlaufen wird - die RegularExpression sollte ein 'begin' mit einem grossgeschriebenen 'AND' nicht als Treffer werten...
Vielen Dank für die Hilfe im voraus Thomas Staack
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de