Emacs は、文字列\
の二重引用符で囲まれた読み取り構文でエスケープする必要があるため、コードがLisp リーダーによって処理されると、単一の文字を含む文字列オブジェクトに"\\"
評価されます。したがって、その単一のバックスラッシュは、その文字列オブジェクトを使用するときに正規表現エンジンが認識するものです。\
ただし、\
正規表現の a にはエスケープ機能も\\
あります。これは、正規表現のシーケンスが単一の に一致することを意味し\
ます。
Emacs 文字列 (の読み取り構文) でシーケンスを表すには\\
、それらのバックスラッシュのそれぞれにバックスラッシュを前置してエスケープする必要があります。
したがって、単一の に一致する正規表現として使用できる which を"\\\\"
含む文字列に評価されます。\\
\
ただし、正規表現文字の代替シーケンス内では、バックスラッシュはエスケープされません。そのため[\]
、文字列 で表される は"[\\]"
、単一のバックスラッシュに一致します。これは、その単一文字セットで唯一可能な一致です。
正規表現として使用されるため、文字列"\\\\"
と"[\\]"
一致するものは同じです。
正規表現としての文字列は、バックスラッシュがまったくない"\\documentclass"
場合と実質的に同じです。これは、正規表現でエスケープされているためです (これは有効ですが、もちろん不要です)。"documentclass"
d
elisp のマニュアルでは、次のように説明されています。
`\' has two functions: it quotes the special characters (including
`\'), and it introduces additional special constructs.
Because `\' quotes special characters, `\$' is a regular
expression that matches only `$', and `\[' is a regular expression
that matches only `[', and so on.
Note that `\' also has special meaning in the read syntax of Lisp
strings (*note String Type::), and must be quoted with `\'. For
example, the regular expression that matches the `\' character is
`\\'. To write a Lisp string that contains the characters `\\',
Lisp syntax requires you to quote each `\' with another `\'.
Therefore, the read syntax for a regular expression matching `\'
is `"\\\\"'.
[...]
As a `\' is not special inside a character alternative, it can never
remove the special meaning of `-' or `]'. So you should not quote
these characters when they have no special meaning either. This would
not clarify anything, since backslashes can legitimately precede these
characters where they _have_ special meaning, as in `[^\]' (`"[^\\]"'
for Lisp string syntax), which matches any single character except a
backslash.
C-hig (elisp) Regexp Special
RET