Parse Query Parameters The challenge is this:

You are given a url that is as follows: 

http://sub.example.com/some/dir/file.php?action=delete&amp;file=test.foo&amp;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:

&gt; https://example.com/index.php?action=delete
...&gt; get(action) #=&gt; delete
&gt; https://this.example.com/cat/index.php?action=delete
...&gt; get(action) #=&gt; delete
&gt; http://example.com, https://action.example.com/actionscript/action.jpg
...&gt; get(action) #=&gt; none
&gt; https://example.com/index.php?genre=action&amp;reaction=1&amp;action=2
...&gt; get(action) #=&gt; 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('.*[&amp;\?]'+k+'=([^&amp;]*).*')))!==null?m[1]:'');}
Retina, 30 27 bytes

!`(?&lt;=^\1 .*[?&amp;](.*)=)[^&amp;]+


This is a full program that expects the key and the URL to be space-separated on STDIN, e.g.

action http://sub.example.com/some/dir/file.php?action=delete&amp;file=test.foo&amp;strict=true


This is essentially just a (.NET-flavoured) regex, which matches the correct value by checking that the preceding key is equal to the first string in the input (using a backreference). The only thing that's a bit odd about the regex is that .NET matches lookbehinds from right to left, which is why the "backreference" actually references a group that appears later in the pattern. The !` instructs Retina to print the actual match (if there is one) instead of the number of matches.

For those who don't regex, here is an annotated version. Read the lookbehind from the bottom up, because that's how it's processed:

(?&lt;=        # A lookbehind. Everything we match in here will not be returned as part of
            # actual match. Start reading this from the corresponding parenthesis.
  ^         # Ensure we're at the beginning of the input, so that we've checked
            # against the entire input key.
  \1        # Backreference to the key to check that it's the one we've asked for.
  [ ]       # Match a space.
  .*        # Consume the rest of the URL.
  [?&amp;]      # Match a ? or a &amp; to ensure we've actually captured the entire key.
  (         # End of group 1.
    .+      # Match the key.
  )         # Capturing group 1. Use this to keep track of the key.
  =         # Make sure we start right after a '='
)           # Start reading the lookbehind here.
[^&amp;]+       # Match the value, i.e. as many non-&amp; characters as possible.