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

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

Re: another newbie question -- auto-mode-alist regexp


From: Michael Slass
Subject: Re: another newbie question -- auto-mode-alist regexp
Date: Mon, 23 Sep 2002 23:15:02 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

"Robert P. J. Day" <address@hidden> writes:

>  i've looked through both the emacs and elisp info pages, and
>i haven't found a simple explanation for the syntax of the 
>expression for setting the auto-mode-alist in my .emacs.
>
>  a couple of examples that are part of the
>(add-to-list 'auto-mode-alist ...  when i bring up online help
>within emacs on the variable auto-mode-alist:
>
>  ("\\.xml\\'" . xml-mode)
>  ("\\.spec$" . rpm-spec-mode)
>  ("\\.php[34]\\'\\|\\.php\\'\\|\\.phtml\\'" . php-mode)
>
>what i haven't figured out yet:
>
>1)  what means the sequence \\', as in what you see after
>   ".xml" in that first example?  i can understand everything
>   else, but that baffles me.
>
>2) i assume that the "$" after .spec means end of string, which
>  is familiar.  i'm curious why a lot of the other suffix regexp
>  matches also don't match to end of string.  like the first one,
>  .xml.  just curious.
>
>3) regarding the php example, couldn't that have been written as
>  
>  ("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode)
>
>
>(this assumes that i still don't know what \\' means.)
>
>  a pointer to the correct online help or info page would do
>nicely.  thanks for your patience.
>
>rday
>
>
>

In a regexp, backslash is used to escape the following character.
Since "." is a metacharacter meaning "any character except newline",
if you want to match an actual dot, like in ".xml", you need to escape
the dot, as in \.

The next wrinkle is that the regexps you're looking at are represented
as string constants.  In string constants, backslashes are used to
introduce escape sequences, or characters that are harder to type.
'\n' represents the newline character, for example.  In order to
introduce a literal backslash into a string constant, you need to
escape the backslash with another one "\\"

Putting that together, in a regexp string constant, "\\." will match
exactly one literal dot.


In emacs regexps, \' is an anchor regexp:

,----
| `\''
|      matches the empty string, but only at the end of the buffer or
|      string being matched against.
`----

You can read all about that in the emacs manual that came with your
emacs.  To read this from within emacs:

C-h i <RET> m emacs <RET> m regexps <RET>

BOL.

-- 
Mike Slass


reply via email to

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