[問題] $ ← Match the end of the line 疑惑

看板Perl作者 (可愛中央處理器)時間13年前 (2012/04/05 18:46), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
#!/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
文章代碼(AID): #1FVNWWC2 (Perl)
文章代碼(AID): #1FVNWWC2 (Perl)