code: def sinatra_path_to_regex(cls, path):
          
          # Return the path if already a (compiled) regex
          if type(path) is cls.regex_type:
              return path
  
          # Build a regular expression string which is split on the '/' character
          regex = [
              "(?P<{}>\w+)".format(segment[1:])
              if cls.sinatra_param_regex.match(segment)
              else segment
              for segment in path.split('/')
          ]
          return re.compile('/'.join(regex))
docs: Converts a sinatra-style path to a regex with named
          parameters.