[gnu.emacs] Help with backslashes

munson@renoir.Berkeley.EDU (Ethan V. Munson) (12/28/88)

I need some help with defining constants to be used later for regular
expression searches.  Suppose I want to search for strings beginning
with an @ sign followed by optional whitespace and then string of 
alpha characters.  I would expect to use something like:

(defconst re1 "@\\s *\\([a-z]*\\)\\1")

Note that I am using parentheses to pull out substrings.  Given this
Lisp sexp, GNU Emacs version 18.51.9 gives the symbol re1 the value:

	"@\\s *\\([a-z]*\\)\\1"

I didn't expect this.  I thought Lisp reader would strip out one
backslash from each pair.  So, when I change the definition to

(defconst re1 "@\s *\([a-z]*\)\1")

the result is 

	"@s *([a-z])1"

Neither of these results is a regular expression that does what I want.
I have to admit that I am clueless about how to solve this in a
straightforward manner.  Does anyone see what I am doing wrong?

Ethan Munson
munson@renoir.Berkeley.EDU
...ucbvax!renoir!munson

piet@ruuinf (Piet van Oostrum) (12/28/88)

In article <27258@ucbvax.BERKELEY.EDU>, munson@renoir (Ethan V. Munson) writes:
`
`(defconst re1 "@\\s *\\([a-z]*\\)\\1")
`							   Given this
`Lisp sexp, GNU Emacs version 18.51.9 gives the symbol re1 the value:
`
`	"@\\s *\\([a-z]*\\)\\1"
`
`I didn't expect this.  I thought Lisp reader would strip out one
`backslash from each pair.

The Lisp reader *DOES* strip the backslash, but the Lisp PRINTER doubles
the backslashes, so you can use the printed form as input. So in your
string there is actually only one backslash per pair. If you don't believe
it, try
	(insert-string 	"@\\s *\\([a-z]*\\)\\1")
-- 
Piet van Oostrum, Dept of Computer Science, University of Utrecht
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
Telephone: +31-30-531806        UUCP: ...!mcvax!hp4nl!ruuinf!piet