I have a URL like so:
http://www.example.com/blah.ashx?ID=fj203-fj230r-3jf030
I was wondering if it's possible to match everything from the ID= to the end of the URL in Ruby, then exclude the ID= from the match? Thanks!
Ruby probably has a built in URL and query-string parser, but this regex should work simply enough:
\?ID=(.*)
I always stick with library methods, lets me sleep better ;-)
require 'cgi'
require 'uri'
uri = URI.parse('http://www.example.com/blah.ashx?ID=fj203-fj230r-3jf030')
params = CGI.parse(uri.query)
id = params["ID"].first
#=> "fj203-fj230r-3jf030"
这样的事情。
"http://www.example.com/blah.ashx?ID=fj203-fj230r-3jf030"[/(?<=ID=)(.*)/]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.