[問題] $ ← Match the end of the line 疑惑
#!/usr/bin/perl -w
$_ = "1\n";
while(/.?$/sg){
print "match:[$&]\n";
}
上面程式碼跑出結果:
match:[1]
match:[
]
match:[]
除了跑出 match:[1] 我比較能理解外
接下來 match:[換行] (雖然我知道後面有修飾子 s 時,可以讓 . 也 match 換行
但不曉得現在 $ anchor 是已經跑到哪邊了,那它可以 match 到換行)
還有最後的 match:[空字串] 也讓我很疑惑
有人能知道 → /.?$/sg ,$ anchor 的行為嗎?
pelre 上只提到說:
「$ Match the end of the line (or before newline at the end)」
但我卻無法從上面那句理解以上程式的行為(苦惱中)
謝謝 ^_^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.59.164.109
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章