Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'subject:help': 0.08; 'messing': 0.09; 'trailing': 0.09; 'zeros': 0.16; 'to:name:python- list@python.org': 0.22; "haven't": 0.24; "i've": 0.25; 'this:': 0.26; 'leave': 0.29; 'message-id:@mail.gmail.com': 0.30; 'decimal': 0.31; 'this.': 0.32; 'figure': 0.32; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'example,': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'remove': 0.60; 'negative': 0.60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=7U16SY0vuqKwZz6xXKdiRd2+CQM9HiaiJEssqdWMY4E=; b=zk3cucdRmpd8uwOzACvkjpVnqzI3Y6IAv/sxkvSjPp6omqD4dXqxwXTqw48vBOR00l z59pT1dw/KIF1QP3jaSJGQD41DYm5pqxp30lYtRGjyXKSy2rOisT4bymdJnHfhEq+za7 ZRhmX4QIXf2R5TMRH8W3PFM8dDJMFdAnGAXOmWNE30D2VQ0uI9w1a3ZdoIiufWiqVocb 9NLyuOuzaRcGbmwFe/Wq2rD1h8S8fFT/Yexhzs4mR7rqjSAud8yj1clk7YOaGAdMGewk DIPYwr2vKRsCSLgzxcgoPhBB6QnsRgfqGWj9ch7izaQDL09WGNuCKYDiWKprfH7Q/RcK 8SWA== MIME-Version: 1.0 X-Received: by 10.180.211.73 with SMTP id na9mr90057258wic.60.1426262757327; Fri, 13 Mar 2015 09:05:57 -0700 (PDT) Date: Fri, 13 Mar 2015 12:05:57 -0400 Subject: regex help From: Larry Martell To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426262765 news.xs4all.nl 2915 [2001:888:2000:d::a6]:59958 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3320 X-Received-Body-CRC: 3711038709 Xref: csiph.com comp.lang.python:87372 I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.0000000000000000,4.56862745000000,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.137254901960000 I want to end up with: 14S,5.0,4.56862745,3.7272727272727271,3.394736842105263,5.7307692307692308,5.7547169811320753,4.9423076923076925,5.7884615384615383,5.13725490196 I have a regex to remove the zeros: '0+[,$]', '' But I can't figure out how to get the 5.0000000000000000 to be 5.0. I've been messing with the negative lookbehind, but I haven't found one that works for this.