[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regular expression

From: Emanuel Berg
Subject: Re: regular expression
Date: Wed, 02 Jul 2014 10:33:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Tak Kunihiro <address@hidden> 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
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:

   (let ((case-fold-search nil)
         (label "Totalt: ")
         (birds 0))
       (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:

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:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]