<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def compile_resource(resource):
 """ Return compiled regex for resource matching """

    return re.compile("^" + trim_resource(re.sub(r":(\w+)", r"(?P<\1>[\w-]+?)",
                      resource)) + r"(\?(?P<querystring>.*))?$")