regular expression help

Tim Harig usernet at ilthio.net
Tue Nov 30 06:45:39 CET 2010


Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo"
>>> pattern = re.compile(r'ccc[^n]*nnn')
>>> pattern.sub("||", m)
'oooo||flfllff||ooo'
>>> # or, assuming that the middle sequence might contain singular or
>>> # double 'n's
>>> pattern = re.compile(r'ccc.*?nnn')
>>> pattern.sub("||", m)
'oooo||flfllff||ooo'
>>>



More information about the Python-list mailing list