[英]# encoding: utf-8 don't working ruby on rails
我在項目中使用ruby 1.9.1。 因此,我需要從字符串中刪除一些注釋,這些注釋將從單詞中粘貼。 如:
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RelyOnVML/>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
所以我寫了一個函數,用text.gsub(/<!--(.*?)-->/s, "")
在助手中刪除它,並在頂級助手文件rb中添加了# encoding: utf-8
在application.rb中定義config.encoding = "utf-8"
,但對我來說似乎不起作用。 我得到的錯誤
ActionView::Template::Error (incompatible encoding regexp match (Windows-31J regexp with UTF-8 string))
在這種情況下,您對我有支持嗎? 謝謝!
沒有一個DOTALL修飾符s
的紅寶石。 只需將s
修飾符更改為m
即可使用。
text.gsub(/<!--(.*?)-->/m, "")
而且您也不需要捕獲任何字符,只需/<!--.*?-->/m
就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.