From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: regular expression Date: Wed, 02 Jul 2014 10:33:01 +0200 Organization: Aioe.org NNTP Server Message-ID: <874mz017pe.fsf@debian.uxu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1404290126 13810 80.91.229.3 (2 Jul 2014 08:35:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Jul 2014 08:35:26 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 02 10:35:22 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 1X2G0e-0007Fh-So for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Jul 2014 10:35:21 +0200 Original-Received: from localhost ([::1]:51745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2G0e-0004hs-Cg for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Jul 2014 04:35:20 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 79 Original-NNTP-Posting-Host: SIvZRMPqRkkTHAHL6NkRuw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:mRN71G1KB1uUQ3NIcwFNIvy6GLQ= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:206227 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:98498 Archived-At: Tak Kunihiro writes: > Use `re-builder' and `query-replace-regexp'. > > Play on (re-builder) with following setup, then copy > regexp that is inside of ". Call > (query-replace-regexp) for substitution. > > (setq reb-re-syntax 'string) re-builder is a gorgeous tool, if it was a girl I would hit on it (her), however, compare two workflows: Method one: 1. get up re-builder 2. start typing - ah, lots of highlights immediately...! 3. maybe my idea for a regexp wasn't that good, I have to rethink it (?) 4. redo 2-3 (the highlights of an incomplete regexp bouncing around, makes me think when I should type and think of what I type) 5. OK, that looks fine, check the screen to see it caught all cases (the regexp method is so the computer can do this, but OK I'll do it - why otherwise would it show?) 6. OK, I think it did catch all (didn't check all, I'm not a machine, but looks good) 7. put the regexp in query-replace-regexp 8. "yes" or "noing" them one by one Method two: 1. think/write code 2. execute it We shouldn't be afraid of the batch, one-hit tools. They are not more difficult to master, and even before we get there, they are less error prone that the interactive pop-shooting all over the place "I caught them all (almost, I think)". Be brave! But that's not all, check out this I just wrote: (progn (insert (let ((case-fold-search nil) (label "Totalt: ") (birds 0)) (save-excursion (replace-regexp (format "^%s[[:digit:]]*\n\n" label) "") (while (re-search-forward "^[a-z]" (point-max) t) (incf birds)) ) (format "\n\n%s%d" label birds) )) (save-buffer) ) Check it out in context here to see what it does: http://user.it.uu.se/~embe8573/birds.txt Yes: by getting better at regexp by doing simple cases in code (like search-and-replaces with patterns), turns out, the regexp can be used to keep track of a small database of birds and keep a digit in sync! (I've heard you need 300 to be a big boy - but even they had to get by the 31st so I'm there in a couple of decades.) Lesson to the computer kids of the world: Do the easy things the (seemingly) difficult but in reality best way, very soon the difficult things will be easy with the exact same method. Remember, "What you once feared, now makes you free. Do it today - in a different way!" I'm getting of the soap box, thanks for this session Emacs people. -- underground experts united: http://user.it.uu.se/~embe8573