From: "Iñaki Baz Castillo" Date: 2008-03-25T23:38:32+09:00 Subject: Help parsing and extracting a num Hi, I'm trying to extract a num from a string. This string is in fact some number of headers separated by \r\n or \n. for now I just need to extract the value of "Content-Length" (case insensitive) header. For example: irb> headers = "Via: via1,via2,\r\n via3\r\nFrom: from_user@domain\nContent-length: 22\r\nTo: to_user@domain\n" I do the following: irb> headers.scan(/content-length\s*:\s*([0-9]*)/i).to_s.to_i => 22 In case the "Content-Length" header exist but has empty value I get 0 with the above code (that's what I need in fact). Is there any way faster to do the same? any help? Thanks a lot. -- Iñaki Baz Castillo