code: protected Pattern convertToRegex(String url) {
          Pattern regex;
          String pattern = null;
          try {
              // Escape any characters that have special meaning in regular expressions,
              // such as '.' and '+'.
              pattern = url.replace(".", "\\.");
              pattern = pattern.replace("+", "\\+");
  
              int lastSlash = pattern.lastIndexOf('/');
  
              String urlRoot = lastSlash > -1 ? pattern.substring(0, lastSlash) : pattern;
              String urlEnd = lastSlash > -1 ? pattern.substring(lastSlash, pattern.length()) : "";
  
              // Now replace "*" with "[^/]" and "**" with ".*".
              pattern = "^" + urlRoot
                      .replace("(\\.(*))", "(\\.[^/]+)?")
                      .replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+?$2")
                      .replaceAll("([^\\*])\\*$", "$1[^/]+?")
                      .replaceAll("\\*\\*", ".*");
  
              if("/(*)(\\.(*))".equals(urlEnd)) {
                  // shortcut this common special case which will
                  // happen any time a URL mapping ends with a pattern like
                  // /$someVariable(.$someExtension)
                  pattern += "/([^/]+)\\.([^/.]+)?";
              } else {
                  pattern += urlEnd
                          .replace("(\\.(*))", "(\\.[^/]+)?")
                          .replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+?$2")
                          .replaceAll("([^\\*])\\*$", "$1[^/]+?")
                          .replaceAll("\\*\\*", ".*")
                          .replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+?)\\\\.")
                          .replaceAll("\\(\\[\\^\\/\\]\\+\\)\\?\\\\\\.", "([^/.]+?)\\?\\\\.")
                  ;
              }
              pattern += "/??$";
              regex = Pattern.compile(pattern);
          }
          catch (PatternSyntaxException pse) {
              throw new UrlMappingException("Error evaluating mapping for pattern [" + pattern +
                      "] from Grails URL mappings: " + pse.getMessage(), pse);
          }
  
          return regex;
      }
docs: Converts a Grails URL provides via the UrlMappingData interface to a regular expression.
  
  @param url The URL to convert
  @return A regex Pattern objet