zancudero at gmail.com
Tue Aug 5 14:06:08 CEST 2008
No, there is a bad way - because of the example doesn't solve arbitrary
amount of <number>.<number>.. blocks.
But the python regexp engine supports for lookahead (?=pattern) and
In those cases patterns are not included into the replaced sequence of
>>> re.sub('(?<=\d)\.(?=\d)', '', '1234.324 abc.100.abc abc.abc')
'1234324 abc.100.abc abc.abc'
On Tue, Aug 5, 2008 at 2:10 PM, Marc 'BlackJack' Rintsch <bj_666 at gmx.net>wrote:
> On Tue, 05 Aug 2008 11:39:36 +0100, Fred Mangusta wrote:
> > In other words I'd like to replace all the instances of a '.' character
> > with something (say nothing at all) when the '.' is representing a
> > decimal separator. E.g.
> > 500.675 ----> 500675
> > but also
> > 1.000.456.344 ----> 1000456344
> > I don't care about the fact the the resulting number is difficult to
> > read: as long as it remains a series of digits it's ok: the important
> > thing is to get rid of the period, because I want to keep it only where
> > it marks the end of a sentence.
> > I was trying to do like this
> > s=re.sub("[(\d+)(\.)(\d+)]","... ",s)
> > but I don't know much about regular expressions, and don't know how to
> > get the two groups of numbers and join them in the sub. Moreover doing
> > like this I only match things like "345.000" and not "1.000.000".
> > What's the correct approach?
> In : re.sub(r'(\d)\.(\d)', r'\1\2', '1.000.456.344')
> Out: '1000456344'
> Marc 'BlackJack' Rintsch
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list