[Tutor] regular expression question

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Mar 9 03:47:23 CET 2005



>
> Regular expressions are a little evil at times; here's what I think you're
> thinking of:
>
> ###
> >>> import re
> >>> pattern = re.compile(r"""dog(?!cat)
> ...                    | (?<=dogcat)""", re.VERBOSE)
> >>> pattern.match('dogman').start()
> 0
> >>> pattern.search('dogcatcher').start()



Hi Mike,

Gaaah, bad copy-and-paste.  The example with 'dogcatcher' actually does
come up with a result:

###
>>> pattern.search('dogcatcher').start()
6
###

Sorry about that!



More information about the Tutor mailing list