Ruby split not working properly

I'm trying to run the following command in irb on a mac:

something.split('\')

This doesn't work either:
something.split("\")

However, this just causes irb not return a result and prevents irb from
being useable and I have to close it.

Any thoughts as to why this is happening? Is this a ruby bug?

It only seems to happen with the \ only..... This is a serious problem
because I am attempting to parse the results of a Linux command which
contains many \'s. I have the exact same issue with:
something.delete('\')

Please help.... Thanks.

···

--
Posted via http://www.ruby-forum.com/.

Try

   something.split('\\')

The backslash is used to escape special characters. In your case to
encode a single quote in the string rather than terminating the string
literal.

IRB is behaving funny because it thinks the string is incomplete, it is
looking for a closing single quote.

The double-backslash encodes as a single backslash in the string.

Gary Wright

···

On Feb 26, 2013, at 11:24 PM, Scott Macri <lists@ruby-forum.com> wrote:

I'm trying to run the following command in irb on a mac:

something.split('\')

1.9.3p125 :001 > 'foo\bar'.split('\\')
  => ["foo", "bar"]

Something like that?

Sam

···

On 02/27/2013 05:24 PM, Scott Macri wrote:

I'm trying to run the following command in irb on a mac:

something.split('\')

This doesn't work either:
something.split("\")

However, this just causes irb not return a result and prevents irb from
being useable and I have to close it.

Any thoughts as to why this is happening? Is this a ruby bug?

It only seems to happen with the \ only..... This is a serious problem
because I am attempting to parse the results of a Linux command which
contains many \'s. I have the exact same issue with:
something.delete('\')

Please help.... Thanks.

'foo\bar'.split('\')

this one doesn't even starts running in irb.
since irb would consider this \' as an escaping single quote,
it's gonna wait for another single quote to end this string variable.

···

On Wed, Feb 27, 2013 at 12:35 PM, Sam Duncan <sduncan@wetafx.co.nz> wrote:

On 02/27/2013 05:24 PM, Scott Macri wrote:

I'm trying to run the following command in irb on a mac:

something.split('\')

This doesn't work either:
something.split("\")

However, this just causes irb not return a result and prevents irb from
being useable and I have to close it.

Any thoughts as to why this is happening? Is this a ruby bug?

It only seems to happen with the \ only..... This is a serious problem
because I am attempting to parse the results of a Linux command which
contains many \'s. I have the exact same issue with:
something.delete('\')

Please help.... Thanks.

1.9.3p125 :001 > 'foo\bar'.split('\\')

=> ["foo", "bar"]

Something like that?

Sam