regular expression help

Yingjie Lan lanyjie at yahoo.com
Tue Nov 30 06:39:45 CET 2010


--- On Tue, 11/30/10, goldtech <goldtech at worldpost.com> wrote:

> From: goldtech <goldtech at worldpost.com>
> Subject: regular expression help
> To: python-list at python.org
> Date: Tuesday, November 30, 2010, 9:17 AM
> The regex is eating up too much. What I want is every
> non-overlapping
> occurrence I think.
> 
> so rtt would be:
> 
> 'oooo||flfllff||ooo'
> 

Hi, I'll just let Python do most of the talk here.

>>> import re
>>> m="oooocccvlvlvlvnnnflfllffccclfnnnooo"
>>> p=re.compile(r'ccc.*?nnn')
>>> p.sub("||", m)
'oooo||flfllff||ooo'

Cheers,

Yingjie


      



More information about the Python-list mailing list