From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: gnuist006@gmail.com Newsgroups: gmane.emacs.help Subject: How to replace-regexp by the average? Date: Fri, 5 Jun 2015 13:30:40 -0700 (PDT) Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1433536525 25816 80.91.229.3 (5 Jun 2015 20:35:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Jun 2015 20:35:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 05 22:35:21 2015 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 1Z0yKm-0003hf-5Z for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 22:35:20 +0200 Original-Received: from localhost ([::1]:49488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0yKl-0002Sb-CZ for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jun 2015 16:35:19 -0400 X-Received: by 10.66.100.163 with SMTP id ez3mr6222122pab.38.1433536241172; Fri, 05 Jun 2015 13:30:41 -0700 (PDT) X-Received: by 10.140.80.168 with SMTP id c37mr71313qgd.39.1433536241067; Fri, 05 Jun 2015 13:30:41 -0700 (PDT) Original-Path: usenet.stanford.edu!news.glorb.com!h15no888538igd.0!news-out.google.com!k20ni45216qgd.0!nntp.google.com!z60no515589qgd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.193.255.242; posting-account=REkl4woAAABFXaU7nL79XtGpnmNCQ415 Original-NNTP-Posting-Host: 108.193.255.242 User-Agent: G2/1.0 Injection-Date: Fri, 05 Jun 2015 20:30:41 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:212493 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:104778 Archived-At: 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