1
有人能解釋這一點:
str = "hi there\r\n\r\nfoo bar"
rgx = /hi there$/
str.match rgx # => nil
rgx = /hi there\s*$/
str.match rgx # => #<MatchData "hi there\r\n\r">
一方面,它似乎像$
不匹配\r
。但是如果我先捕獲所有的空格,其中包括\r
,那麼$
突然確實看起來與第二個\r
匹配,而不是繼續捕獲尾隨的"\nfoo bar"
。
這裏有關於連續\r\n
序列的一些特殊規則嗎? $
上的文檔簡單地說它將匹配「行尾」,這不能解釋這種行爲。
底線問題:\ r不與$匹配,也不是「\ r \ n」,即使放入和其他東西確實將它們理解爲換行符以用於顯示。 – eagspoo