Thomas Gantner
7/26/2007 10:59:00 PM
on Thu 26. July 2007 02.37, scomboni@gmail.com wrote:
> On Jul 25, 7:05 pm, Phrogz <phr...@mac.com> wrote:
>> On Jul 25, 4:59 pm, scomb...@gmail.com wrote:
>>
>> > For example if I have a file called filename.txt and I want to search
>> > for this ---> "Compression : JPEG (old-style)"
>> > but only return everything to the right of the delimitator?
>>
>> C:\>irb
>> irb(main):001:0> s = "Foo : Bar"
>> => "Foo : Bar"
>> irb(main):002:0> s.split ":"
>> => ["Foo ", " Bar"]
>> irb(main):003:0> s.split(":").last
>> => " Bar"
>>
>> ...or did you want the leading whitespace chomped?
>>
>> irb(main):004:0> s.split( /\s*:\s*/ )
>> => ["Foo", "Bar"]
>> irb(main):005:0> s.split( /\s*:\s*/ ).last
>> => "Bar"
>
> I was looking at this method as well. I was having trouble though as I
> know the left hand side column so for this example the Compression
> portion then the colon : the remainder could be anything for instance
> a description with lots of text and could also contain a additional
> colon. At the shell prompt I could grep "Compression" | cut -d: -f2-
> and that would grab everything...
> So it sounds like I'm looking in the correct area but Im just not
> pulling it all together. I will keep at it if you have additional info
> to point to that would be great..and appreciated.
> Thanks again.
split takes an optional second parameter <limit>, defining how many elements
the resuting array shall have at most
'foo : bar : baz'.split(/\s*:\s*/, 2)
=> [ "foo", "bar : baz" ]
-Thomas
--
<sig. under construction>