all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: Robert Thorpe <rt@robertthorpeconsulting.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>,
	Marcin Borkowski <mbork@wmi.amu.edu.pl>
Subject: Re: Regex replace for numbers
Date: Fri, 3 Oct 2014 09:45:50 +0700	[thread overview]
Message-ID: <CAP_d_8Wi-sLdpRoSrFOevZjngZ7_3-u0xgSEACM=jHR40cGK=g@mail.gmail.com> (raw)
In-Reply-To: <87tx3mx73n.fsf@robertthorpeconsulting.com>

On Fri, Oct 3, 2014 at 8:41 AM, Robert Thorpe
<rt@robertthorpeconsulting.com> 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’t touch instances which have a letter immediately after it:

1234.5678000s

If you want that too, try this:

\([0-9]+\.[0-9]*?\)0+\([^0-9]|\') replace with \1\2



  reply	other threads:[~2014-10-03  2:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-03  0:33 Regex replace for numbers Robert Thorpe
2014-10-03  1:07 ` Marcin Borkowski
2014-10-03  1:41   ` Robert Thorpe
2014-10-03  2:45     ` Yuri Khan [this message]
2014-10-03  5:25 ` Nicolas Richard
     [not found] ` <mailman.10347.1412313926.1147.help-gnu-emacs@gnu.org>
2014-10-03 11:43   ` Udyant Wig
2014-10-03 14:40     ` Nicolas Richard
2014-10-03 19:22       ` Robert Thorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP_d_8Wi-sLdpRoSrFOevZjngZ7_3-u0xgSEACM=jHR40cGK=g@mail.gmail.com' \
    --to=yuri.v.khan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    --cc=rt@robertthorpeconsulting.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.