From: Robert Klemme Date: 2010-06-23T01:28:42+09:00 Subject: Re: Extract value 2010/6/22 Matthew Bloch : > On Wed, 2010-06-23 at 00:36 +0900, Manuel Manu00 wrote: >> Hello >> >> I would like to parse or regexp the following string : >> >> > > matched = /google_ad_client\s*=\s*\"([^"]+)\"/.match(string) > google_ad_client = matched ? matched[1] : nil > > seems flexible-ish, and might do what you want. You can also use String#[] like this: irb(main):001:0> s=< irb(main):003:0" google_ad_client = "pub-9423056098431875"; irb(main):004:0" /* 300x250, created 6/10/09 */ irb(main):005:0" google_ad_slot = "1755518182"; irb(main):006:0" google_ad_width = 300; irb(main):007:0" google_ad_height = 250; irb(main):008:0" irb(main):009:0" STR => "\n" irb(main):010:0> s[/google_ad_client\s*=\s*"([^"]*)"/, 1] => "pub-9423056098431875" irb(main):011:0> If there is no match, you get nil. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/