regular expression help

goldtech goldtech at worldpost.com
Tue Nov 30 06:17:16 CET 2010


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'

just like findall acts but in this case I want sub to act like that.

Thanks




More information about the Python-list mailing list