regular expression help

Tim Harig usernet at ilthio.net
Tue Nov 30 00:34:59 EST 2010


On 2010-11-30, goldtech <goldtech at worldpost.com> wrote:
> Hi,
>
> say:
>>>> import re
>>>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo"
>>>> re.compile(r'ccc.*nnn')
>>>> rtt=pppp.sub("||",m)
>>>> rtt
> 'oooo||ooo'
>
> The regex is eating up too much. What I want is every non-overlapping
> occurrence I think.
>
> so rtt would be:
>
> 'oooo||flfllff||ooo'

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'
>>>



More information about the Python-list mailing list