newbie - Regular expression help
William Park
parkw at better.net
Mon Nov 20 18:12:59 EST 2000
On Sun, Nov 19, 2000 at 07:46:17AM -0500, Satheesh Babu wrote:
> Hi all,
>
> I need to scan a string and replace all occurrences of
> "./" with null. But "../" shouldn't get changed.
>
> Stupid way is to first replace ../ with AbRaCaDaBrA
> and then replace ./ with null and then replace
> AbRaCaDaBrA with ../
>
> There should be a simpler solution.
>
> Anyone, please...
>
> Thx
Try
re.sub('([^.])\./', r'\1', 'aa../bb./cc')
re.sub('(?<!\.)\./', '', 'aa../bb./cc')
---William Park, Open Geometry Consulting
More information about the Python-list
mailing list