help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Q: How to copy a string in a text into a variable?


From: Eric Marsden
Subject: Re: Q: How to copy a string in a text into a variable?
Date: Thu, 19 Sep 2002 13:27:27 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.2

>>>>> "gd" == gnuist  <gnuist007@hotmail.com> writes:

  gd> But you have a number of pearls or possibly bugs that I could
  gd> not verify. Specifically, I am interested in a dissection of the
  gd> regular expression

  ecm> (when (looking-at "[A-Z]\\{3\\}[0-9]+")

  gd> and the conundrum is in \\{3\\}, a construct, which has no
  gd> reference in the info page on emacs regular expressions.

my Emacs manual has the following:
  
,----
| `\{N\}'
|      is a postfix operator that specifies repetition N times--that is,
|      the preceding regular expression must match exactly N times in a
|      row.  For example, `x\{4\}' matches the string `xxxx' and nothing
|      else.
`----

(You also have to know that in an elisp string, the '\' character is
an escape character, so you have to double it to get a literal '\'.)

  gd> You may as well explain the wisdom in the use of
  gd> 
  gd> (save-excursion         ; ???
  gd> (save-match-data      ; ???
  gd> 
  gd> which I fail to see despite seeing description on them.

the save-excursion is to avoid having command execution move point,
which is more polite. The save-match-data is due to me having used a
regexp function (looking-at), which sets the match data (some global
variables that allow functions like match-string to work); it's more
polite to save the match data to avoid changing it in the back of
another function.

(The save-match-data is probably not necessary, since this was inside
a command run from the keyboard, so it's unlikely to interfere with
other functions.)
  
-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>


reply via email to

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