Complete rewrite of extraction.

This will fix issues where adding a question mark earlier in the URI
will cause the entire string after it to become the query-string and
fail to match patterns in unique regex matches.