From: "村岡 恒輝" Date: 2013-09-28T19:41:49+09:00 Subject: [ruby-list:49610] ダブルバックスラッシュとバックスラッシュの入り混じる文字列のsplit --001a113364607785ba04e76f42f2 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit 初めまして、村岡と申します。 'first\\ sec\ond\\ third\\' という文字列をバックスラッシュは無視し、ダブルバックスラッシュでsplitすることで ["first", " sec\ond", " third"] を得たいのですが、 >> 'first\\ sec\ond\\ third\\ fourth\\' #=> "first\\ sec\\ond\\ third\\ fourth\\" >> "first\\ sec\ond\\ third\\ fourth\\" #=> "first\\ second\\ third\\ fourth\\" と、rubyに文字列を読み込ませた瞬間、メタ文字が解釈されてダブルバックスラッシュとバックスラッシュの見分けがつかなくなり、splitできなくなってしまうように思われるのですが、良い方法はあるのでしょうか。 アドバイス頂ければ幸いです。 -- 村岡 magi.select@gmail.com --001a113364607785ba04e76f42f2 Content-Type: text/html; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit

初めまして、村岡と申します。

'first\\ sec\ond\\ third\\'

という文字列をバックスラッシュは無視し、ダブルバックスラッシュでsplitすることで

["first", " sec\ond", " third"]

を得たいのですが、

>> 'first\\ sec\ond\\ third\\ fourth\\' #=> "first\\ sec\\ond\\ third\\ fourth\\"
>> "first\\ sec\ond\\ third\\ fourth\\" #=> "first\\ second\\ third\\ fourth\\"

と、rubyに文字列を読み込ませた瞬間、メタ文字が解釈されてダブルバックスラッシュとバックスラッシュの見分けがつかなくなり、splitできなくなってしまうように思われるのですが、良い方法はあるのでしょうか。
アドバイス頂ければ幸いです。

--
村岡
magi.select@gmail.com

--001a113364607785ba04e76f42f2--