From: Robert Klemme Date: 2010-03-04T01:55:15+09:00 Subject: Re: Url parsing in ruby 2010/3/3 John Ydil : > Hello, > > I use ruby to make some scriptings inside an html page. > I made a form to pass variable in an URL. > I need this variable in my ruby code, how can i get this variable ? > > my URL looks like http://localhost/mypage.rbx?var=nas002001 > > I need the value after var= > > Thanks for your help. Here's one way to do it: $ irb19 -r uri irb(main):001:0> u = URI.parse "http://localhost/mypage.rbx?var=nas002001" => # irb(main):002:0> v = u.query[/(?<=\A|&)var=([^&]*)/, 1] => "nas002001" Note, error checking is missing from this example and it's probably also not very robust. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/