The challenge is this:
You are given a url that is as follows:
http://sub.example.com/some/dir/file.php?action=delete&file=test.foo&strict=true
There can be either http
or https
, there can be any number of subdomains or directories, and the end file can have any name.
You are to create a full program (that can be compiled/interpreted) that when given a key will return the correct value and if no key is found it will return an empty string.
For example:
> https://example.com/index.php?action=delete
...> get(action) #=> delete
> https://this.example.com/cat/index.php?action=delete
...> get(action) #=> delete
> http://example.com, https://action.example.com/actionscript/action.jpg
...> get(action) #=> none
> https://example.com/index.php?genre=action&reaction=1&action=2
...> get(action) #=> 2
There are no language restrictions and score is calculated a 1 point for every byte. Smallest score wins.
To clarify:
- You do not need to handle URL encoding
- The script only needs to run once and produce a result
- The script can take any input form: STDIN, Prompt, even passed as a function argument
Example:
Javascript, 101 105 bytes
function p(k){var m;return((m=location.href.match(new RegExp('.*[&\?]'+k+'=([^&]*).*')))!==null?m[1]:'');}
action
):http://example.com
,https://action.example.com/actionscript/action.jpg
,https://example.com/index.php?genre=action&reaction=1&action=2
\$\endgroup\$ – Sp3000 Jun 5 '15 at 1:59