探しま〜す。
探しま〜す。大丈夫,恨みません。
どもども。
Emacs Lisp で,与えられた文中から,ある文字列を探したい。
ただし,文の末尾から探したい。
例えば・・・。
This is a foo that is not same as the foo in that sentence written by foo named foo.
という文があったときに,仮にマルタイの関数名を string-match-backward とすると,
;; とりあえず文の長さ (length "This is a foo that is not same as the foo appeared in that sentence written by foo.") => 83 ;; プロトタイプは,string-match に倣って, ;; (string-match-backward REGEXP STRING &optional START) がいいね。 ;; 一番最後の foo の出現 (string-match-backward "foo" "This is a foo that is not same as the foo appeared in that sentence written by foo.") => 79 ;; 一番最後の1つ前の foo の出現 (string-match-backward "foo" "This is a foo that is not same as the foo appeared in that sentence written by foo." 79) => 38
てな感じに動作して欲しい。
他の挙動は,string-match と同じで,match-beginning, match-end とかも使える方向で。
探した感じなかった。search-backward, re-search-backward を使う感じ?
ググってみたら,
http://www.emacswiki.org/emacs/ElispCookbook
なんていう素敵ページを見つけられたのは,収穫。
以上を踏まえると,with-temp-buffer 使って,ポイントをケツに移動させて,
re-search-backward をガシガシする感じかなぁ。
あぁ,検索は複数回したいんです。
substring を使ってみるとかとも思ったけど,効率悪すぎそう。
だれか以上のような条件を満たす関数を知っていたら教えてください。
なければ自分で書く必要があるなぁ。
けど,string-match でも,(match-beginning 0) を記録しながらループすればいける?
けど,それだと出現個数を最初に調べる必要があるだろうなぁ。
なんか重そう。。。
うーん,悩ましい。