作者: Bunta
日時: 2008/9/04(00:55)
------------------------------
`\`'
     Matches only at the start of pattern space.  This is different
     from `^' in multi-line mode.
`\''
     Matches only at the end of pattern space.  This is different from
     `$' in multi-line mode.
		(from sed 4.1.2 sed.info)
------------------------------

 以下すべてBREモードでの実験です。

== First, Seds' behavior with regard to "^" and "$" in multi-line.

--- test.txt ---
aaa
bbb
----------------
--- test.sed ---
# (eg|s|mb|onig)sed	
N
s/^/T/gM			# with /M, 'T' stands for Top
----------------
# results; 「Taaa\nTbbb」, all of them, OK!

--- test.sed ---
# four seds
N
s/^/T/g				# without /M, 
----------------
results:
----------------
#onigsed		# different from the three results below.
Taaa			# perhaps, oniguruma's spcifications
Tbbb			# that is, correct output???   (*)★
----------------
#mbsed, egsed, ssed
Taaa
bbb
----------------

--- test.sed ---
# four seds
N
s/$/B/Mg			# with /M, 'B' stands for Bottom
----------------
# results: 「aaaB\nbbbB」all of them, OK

--- test.sed ---	# results: 「aaa\nbbbB」, all of them, OK
# four seds		# well, then (*) above looks dubious, bug?
N
s/$/B/g				# without /M
----------------


=== Now, let's tackle with `\`' and `\''

--- test.sed ---	# `\`' result, four of them, perfect! even Onig!
# four seds		# of course, 「Taaa\nbbb」 was the result.
N
s/\`/T/
----------------
--- test.sed ---	# `\'' result, four of them, perfect! even Onig!
# four seds		# of course, 「aaa\nbbbB」 was the result.
N
s/\`/B/
----------------


 >Bruce.さん(そして皆さま)
 というわけで、たぶん、下と上がバッティングしてしまっているのではないか
と、僕は考えています。間違っていますでしょうか。★の箇所が直れば、少しよ
いのかな、と思っております。

------------------------------
  \Z      end of string, or before newline at the end
  \z      end of string
		(oniguruma.docより)
------------------------------

 文字列末尾に改行文字がある場合には、「$」が改行文字の前の"empty string"
を指す、というのは、perlとrubyを知らないものですから、まだよく分かってい
ないのですけれど。


Bunta