From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Regex replace for numbers Date: Fri, 3 Oct 2014 09:45:50 +0700 Message-ID: References: <87mw9ex8nk.fsf@wmi.amu.edu.pl> <87tx3mx73n.fsf@robertthorpeconsulting.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1412304385 31605 80.91.229.3 (3 Oct 2014 02:46:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 3 Oct 2014 02:46:25 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" , Marcin Borkowski To: Robert Thorpe Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 03 04:46:18 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XZssr-00031T-FO for geh-help-gnu-emacs@m.gmane.org; Fri, 03 Oct 2014 04:46:17 +0200 Original-Received: from localhost ([::1]:37709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZssq-0007Ha-Sc for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Oct 2014 22:46:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZssd-0007HK-Sw for help-gnu-emacs@gnu.org; Thu, 02 Oct 2014 22:46:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZssY-0000Yp-6K for help-gnu-emacs@gnu.org; Thu, 02 Oct 2014 22:46:03 -0400 Original-Received: from mail-ig0-x229.google.com ([2607:f8b0:4001:c05::229]:46822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZssY-0000XY-10 for help-gnu-emacs@gnu.org; Thu, 02 Oct 2014 22:45:58 -0400 Original-Received: by mail-ig0-f169.google.com with SMTP id uq10so364440igb.0 for ; Thu, 02 Oct 2014 19:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=iDBoVlAeleTdzHx090eqcqWTBaPApRIOir+cryagT6U=; b=ZIT+CGWQSwKTubsu/MP0F1chs3//nsvZkdOdKsJd2S70Bo2QYeiX12tZsrgPt0mzfu vGi+uLkjJsIyd8cOL96Afv5ltTyKEs7O7KDjBLqZ881mu/4z5vImmY/iXuCJiDZw9i7W Em4Sb7qmRawwX0ySfNlSLOfC99aH8eAmN1qIR9hKKqL8yZGTR2hzAO73JtYGCe0kpjt9 L2qwAdHyvliT/vxUVUV9vsMf6H3XOE499BI8zZ6QsBVoYiTlPqQ3h7zmEYVl99ywxizB 97UyCHepDGIvCGSikReV+q75YyHttejwZtuFtDpFAp3h2vX7fiFB47jWq671L0OqPolm qlHw== X-Received: by 10.50.43.193 with SMTP id y1mr10277617igl.32.1412304351032; Thu, 02 Oct 2014 19:45:51 -0700 (PDT) Original-Received: by 10.107.4.79 with HTTP; Thu, 2 Oct 2014 19:45:50 -0700 (PDT) In-Reply-To: <87tx3mx73n.fsf@robertthorpeconsulting.com> X-Google-Sender-Auth: agMHnrcU1X4NtYdnrcB4f4p_kXU X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::229 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100241 Archived-At: On Fri, Oct 3, 2014 at 8:41 AM, Robert Thorpe wrote: >> \([0-9]+\)\.\([0-9]*?\)0+ RET >> \1.\2 RET > > That needs C-M-%, regexp-replace. If I have a number like 456.0040 then > it replaces the first two zeros giving 456.40, which is wrong. It seems > that shortest-match regexps aren't very useful here. If I remove the ? > in the regexp then it works, but it only removes one layer of zeros at a > time, so e.g. 567.45000 becomes 567.4500. So what you need to match is a string of digits, then a decimal point, then a non-greedy string of digits, then a (possibly empty but greedy) string of zeros, and finally an end of word. \([0-9]+\.[0-9]*?\)0+\> replace with \1 Note that this won=E2=80=99t touch instances which have a letter immediatel= y after it: 1234.5678000s If you want that too, try this: \([0-9]+\.[0-9]*?\)0+\([^0-9]|\') replace with \1\2