作者cutecpu (可爱中央处理器)
看板Perl
标题[问题] $ ← Match the end of the line 疑惑
时间Thu Apr 5 18:46:53 2012
#!/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