Emacs らくらく入門
なか見! 検索
    環境
  構成
節目次
  目次(1-3)
  目次(4-5)
  目次(6-9)
  目次(付録)
  コラム目次
正誤表
参照
  本文内 URL
  anoncvs
本文補足
    p142 正規表現
    p145 c という形式の
      まとめ
    p145 分類
    p185 (outline-mode)
    p208 Wanderlust/Meadow
    p252 (POP-before..)
    p252 (SMTPauth)
    p257 (draft)
    p262 (Relay)
    p286 AucTex
    p287 auto-insert
    p303 (ssh)
    p351 .Xdefaults
    p399 .emacs(Mac OS X)
    p400 ことえり patch
      橋本さんから
    p400 inline update
      mule-ucs
      bash と tcsh の読替
    p400 inline update
      mule-ucs
      bash と tcsh の読替
    p400 20060319 版
      ~/.emacs の設定
      inline を有効に
      transparency の設定
      bash と tcsh の読替
      Carbon package
    p401 tamago
    p411 emacs-w3m
    p412 auctex
    p413 mu-cite
    p415 x-face
    p425 FreeWnn (FC3)
      inetd
      自動起動
    p435 w3m
書けなかったこと
  grep
    egrep
  Anthy
Meadow
  Windows で Emacs
    setup.exe
    ImageMagick
    HOME
    .emacs
その他
  dot.emacs
  出版社と販売
  rank
  関連書籍

Emacs の始め方 | dot.emacs | application | 便利なツール Emacs らくらく入門
Last Update: "2007/01/10 11:04:24 makoto"

p145 c という形式の

p 145 にある「表 3.27 正規表現」の要素の
文字の種類 それらに一致それら以外に一致
c という形式の文字 \sc \Sc
の部分ですが、この「c という形式の文字」が何であるかの説明が抜けていました。 これは構文種別、あるいは構文クラス、英語なら Syntax Class という考え方の表現方法です。
構文種別(Syntax Classes):
http://www.bookshelf.jp/texi/elisp-manual-20-2.5-jp/elisp_35.html#SEC566
正規表現 構文種別 その種別に属する文字
\sc の例 c の意味 具体的文字
\s-
\s (空白)
\sw (英)単語を作る文字 A-Za-z0-9
\s_ シンボルを作る文字 上記 と $&*+-_<> の文字
構文種別とは、現在編集中の文字の一つ一つを文法的に分類して、その文字がその分類のどれに属するか という性質です。簡単に言えば、
  • cat とか dog とか fox は「単語」という分類である
  • 1 2 3 は数字である
  • ' ' は空白文字である
などです。 現在編集中の内容について、 そのモードによって、 どのような文字がどのような構文種別に属するかが決まります。
編集モードが決まる 構文種別の全体が決まる 文字一つ一つが、どの構文種別要素に属するか決まる
という図式になります。 現在編集中のモードで、 その構文種別全体がどうなっているかは C-h s (M-x describe-syntax) で表示してくれます。 その時の表示は三つ組で、そのそれぞれは:
その種別に属する文字構文種別要素 説明
どのような文字が(編集中の文字) どのような文字で表わされていて (正規表現) その意味は何であるか
というようになっています。 それで得られる説明の具体的な表示例は、 例えば次のようなものです。
The parent syntax table is:
C-@ .. SPC	  	which means: whitespace
!		. 	which means: punctuation
"		" 	which means: string
#		. 	which means: punctuation
$ .. %		w 	which means: word
&		_ 	which means: symbol
'		. 	which means: punctuation
(		()	which means: open, matches )
)		)(	which means: close, matches (
* .. +		_ 	which means: symbol
,		. 	which means: punctuation
-		_ 	which means: symbol
.		. 	which means: punctuation
/		_ 	which means: symbol
0 .. 9		w 	which means: word
: .. ;		. 	which means: punctuation
< .. >		_ 	which means: symbol
? .. @		. 	which means: punctuation
A .. Z		w 	which means: word
[		(]	which means: open, matches ]
\		\ 	which means: escape
]		)[	which means: close, matches [
例えば、この中の 6 行目に「どのような文字で表わされていて」が 「w」の文字という行があります:
その種別に属する文字構文種別要素 説明
どのような文字がどのような文字で表わされていてその意味は何であるか
$ .. % w which means: word
この行の意味するところは、 「$ .. %」 が、(w の前に \s を付けた) \sw の正規表現に一致します。 上の表を良く見ると、 「どのような文字が表わされて」が w になっている のは、三つあります
$ .. %, 
0 .. 9, 
A .. Z 
です。これらの文字はどれでも \sw の正規表現に一致します。

上の表の第三項目にある用語の 意味は次のようなものです。

whitespace 空白文字
punctuation 単語の区切
string 文字列
word 単語
symbol 記号
open 開括弧
close 閉括弧
escape 回避文字
まとめ
  • 正規表現で \s や \S は構文種別を表わす
  • 構文種別は、その次に来る文字でどの種別かを表わす
  • その文字、構文種別文字は、モードによって違う場合もある
  • \s を使った場合には、「その構文種別に属す文字」
  • \S を使った場合には、「その構文種別に属さない文字」となる
    (これは、Perl の s と S に似ているが、Perl は直接に表わすが、Emacs では 間接になっている)
    perl emacs
    空白文字 \s \s_
    非空白文字 \S \S_
    この表では、emacs の方には後に空白文字が一つ付いています (下線 _ はこの表で説明する都合上、空白を表しています)
emacs-21 | application | dot.emacs
Last Update: Sat, 07 Jun 2014 22:16:17 GMT 1.66 2008/03/08