I want to get ASIA
from following sample.
/scripts/skw.asp?term=&department=ASIA
Do you know how can I extract department value from whole text.
I want to get ASIA
from following sample.
/scripts/skw.asp?term=&department=ASIA
Do you know how can I extract department value from whole text.
string = "/scripts/skw.asp?term=&department=ASIA&a=b"
puts string[/department=(\w+)/, 1] # => "ASIA"
or you can parse this as query(which is in my opinion more appropriate):
require 'cgi'
string = "/scripts/skw.asp?term=&department=ASIA&a=b"
query = string.split('?')[1] # => "term=&department=ASIA&a=b"
parsed_query = CGI::parse(query) # => {"term"=>[""], "department"=>["ASIA"], "a"=>["b"]}
puts parsed_query['department'][0] # => "ASIA"
str = '/scripts/skw.asp?term=&department=ASIA'
You could use a capture group:
str[/\bdepartment=(.+$)/, 1]
#=> "ASIA"
or a positive lookbehind:
str[/(?<=\bdepartment=).+$/]
#=> "ASIA"