我想創建一個Ruby模式來替換除了最後一個字母以外的所有字符。Ruby模式完全匹配
例如,更換所有:
"}"
以字符串:
"} something "
打開這個字符串:
"{ anything } { anything } { anything }"
到:
"{ anything } something { anything } something { anything }"
編輯:
我到目前爲止已經使用:
replaceString = "} something"
string.gsub("}", replaceString).reverse.sub(replaceString.reverse, "}").reverse
,但我不認爲這是非常有效的。
我們建議您[研究您的問題(http://stackoverflow.com/questions/how-to-ask)。如果你[已經嘗試過](http://whathaveyoutried.com/),請將其添加到問題中,如果不是,先研究並嘗試你的問題,然後再回來。 – 2012-07-25 18:04:36