If you are trying to use a regex, I think it would look something like:
Matcher match = /([^\?]+).*/.matcher(doc['request'].value);
if (match.matches()) {
return match.group(1);
} else {
// something is wrong? the path is malformed, decide what to return or throw an error
}