From: gnuist006@gmail.com
To: help-gnu-emacs@gnu.org
Subject: How to replace-regexp by the average?
Date: Fri, 5 Jun 2015 13:30:40 -0700 (PDT) [thread overview]
Message-ID: <b1321cdb-a942-4ad3-b04b-64e235d56870@googlegroups.com> (raw)
Given strings of this type
TOKEN 123.456 12.3456 1234.56
replace by
TOKEN 67.9008 623.453
where the first number is the average, ie what you get from the evaluation of
(/ (+ 123.456 12.3456) 2.0)
and second is also the average, ditto
(/ (+ 1234.56 12.3456) 2.0)
both upto 6 significant digits.
I tried this but it does not work.
(save-excursion (replace-regexp "TOKEN \\([0-9\\.]+\\) \\([0-9\\.]+\\) \\([0-9\\.]+\\)" (concat "TOKEN (format "6.6f" (/ (+ \\1 \\2) 2.0)) (format "6.6f" (/ (+ \\2 \\3) 2.0)) ) ))
Any help in improving while keeping it readable one-liner sexp and maintaining the use of \\1 \\2 \\3 etc if possible ... ?
Cheers,
Bolega
next reply other threads:[~2015-06-05 20:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 20:30 gnuist006 [this message]
2015-06-05 21:12 ` How to replace-regexp by the average? John Mastro
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=b1321cdb-a942-4ad3-b04b-64e235d56870@googlegroups.com \
--to=gnuist006@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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.