all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to replace-regexp by the average?
@ 2015-06-05 20:30 gnuist006
  2015-06-05 21:12 ` John Mastro
  0 siblings, 1 reply; 2+ messages in thread
From: gnuist006 @ 2015-06-05 20:30 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-05 21:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-05 20:30 How to replace-regexp by the average? gnuist006
2015-06-05 21:12 ` John Mastro

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.