Convert a Servlet Mapping to a compiled {@link Pattern}
176871
public static Pattern mappingToRegex(String mapping)
   {
      return Pattern.compile(mapping.replaceAll("\\.", "\\.")
               .replaceAll("^\\*(.*)", "^(.*)$1\\$")
               .replaceAll("(.*)\\*$", "^$1(.*)\\$"));
   }
941703
private ActionPatternHolder convertStringToPattern(String line) {
        ActionPatternHolder holder = new ActionPatternHolder();
        String[] strs = org.apache.commons.lang.StringUtils.split(line, "|");
        if (strs.length != 2) {
            throw new IllegalArgumentException("illegal expression: " + line);
        }
        Pattern compiledPattern;
        Perl5Compiler compiler = new Perl5Compiler();
        try {
            holder.setActionName(strs[0]);
            compiledPattern = compiler.compile(strs[0], Perl5Compiler.READ_ONLY_MASK);
            holder.setActionPattern(compiledPattern);
        } catch (MalformedPatternException mpe) {
            throw new IllegalArgumentException("Malformed regular expression: " + strs[0]);
        }

        try {
            holder.setMethodName(strs[1]);
            compiledPattern = compiler.compile(strs[1], Perl5Compiler.READ_ONLY_MASK);
            holder.setMethodPattern(compiledPattern);
        } catch (MalformedPatternException mpe) {
            throw new IllegalArgumentException("Malformed regular expression: " + strs[1]);
        }

        return holder;
    }
163518
String getPattern() {
        final StringBuilder result = new StringBuilder();

        if (myPrefix != null) {
            result.append(myPrefix);
        }
        if (mySuffixes != null) {
            result.append("*");
            for (final Literal sub : mySuffixes) {
                result.append(sub);
                result.append("*");
            }
        }
        if (myPostfix != null) {
            result.append(myPostfix);
        }
        return result.toString();
    }
248295
function pattern(toMatch) {
  var regexps = getQMarkPaths(toMatch, [])

  //reassign array to compiled regular expressions
  regexps.forEach(function(aPath, ix) {
    regexps[ix] = compile(aPath, true).regexp //'true' tells regexp compiler to math till end => '$'
  })


  if (regexps.length === 1) { //fast case
    var reg = regexps[0]
    return reg.test.bind(reg)
  } else { //test each potential path
    return function (testAgainst) {
      for (var i = 0; i < regexps.length; i++) {
        if (regexps[i].test(testAgainst)) return true
      }

      return false
    }
  }
}
1227982
private static Pattern compileAssignPattern(String name) {
        return Pattern.compile(
                String.format("\\b(__)?%s(__)?\\b *= *(['\"]+)(.*?)\\3", name),
                REGEX_OPTIONS);
    }
208004
public static Pattern compilePattern(final String expr) {
        Pattern pattern;
        final int lastChar = expr.length() - 1;
        if (expr.charAt(0) == '/' && expr.charAt(lastChar) == '/') {
            pattern = Pattern.compile(expr.substring(1, lastChar));
        } else {
            pattern = Pattern.compile(Pattern.quote(expr));
        }
        return pattern;
    }
120175
private void addAllWithFilter(Map<String, String> toMap, Map<String, String> fromMap, IncludeExcludePatterns pattern) {
        for (Object o : fromMap.entrySet()) {
            Map.Entry entry = (Map.Entry) o;
            String key = (String) entry.getKey();
            if (PatternMatcher.pathConflicts(key, pattern)) {
                continue;
            }
            toMap.put(key, (String) entry.getValue());
        }
    }
1154110
private static PathMapping pathStringMapping(String pathPrefix, Method method,
                                                 Set<Annotation> methodAnnotations) {
        pathPrefix = ensureAbsolutePath(pathPrefix, "pathPrefix");
        if (!pathPrefix.endsWith("/")) {
            pathPrefix += '/';
        }

        final String pattern = findPattern(method, methodAnnotations);
        final PathMapping mapping = PathMapping.of(pattern);
        if ("/".equals(pathPrefix)) {
            // pathPrefix is not specified or "/".
            return mapping;
        }

        if (pattern.startsWith(EXACT)) {
            return PathMapping.ofExact(concatPaths(
                    pathPrefix, pattern.substring(EXACT.length())));
        }

        if (pattern.startsWith(PREFIX)) {
            return PathMapping.ofPrefix(concatPaths(
                    pathPrefix, pattern.substring(PREFIX.length())));
        }

        if (pattern.startsWith(GLOB)) {
            final String glob = pattern.substring(GLOB.length());
            if (glob.startsWith("/")) {
                return PathMapping.ofGlob(concatPaths(pathPrefix, glob));
            } else {
                // NB: We cannot use PathMapping.ofGlob(pathPrefix + "/**/" + glob) here
                //     because that will extract '/**/' as a path parameter, which a user never specified.
                return new PrefixAddingPathMapping(pathPrefix, mapping);
            }
        }

        if (pattern.startsWith(REGEX)) {
            return new PrefixAddingPathMapping(pathPrefix, mapping);
        }

        if (pattern.startsWith("/")) {
            // Default pattern
            return PathMapping.of(concatPaths(pathPrefix, pattern));
        }

        // Should never reach here because we validated the path pattern.
        throw new Error();
    }
1297025
function compile(self) {

  // Load & clone RE patterns.
  var re = self.re = require('./lib/re')(self.__opts__);

  // Define dynamic patterns
  var tlds = self.__tlds__.slice();

  self.onCompile();

  if (!self.__tlds_replaced__) {
    tlds.push(tlds_2ch_src_re);
  }
  tlds.push(re.src_xn);

  re.src_tlds = tlds.join('|');

  function untpl(tpl) { return tpl.replace('%TLDS%', re.src_tlds); }

  re.email_fuzzy      = RegExp(untpl(re.tpl_email_fuzzy), 'i');
  re.link_fuzzy       = RegExp(untpl(re.tpl_link_fuzzy), 'i');
  re.link_no_ip_fuzzy = RegExp(untpl(re.tpl_link_no_ip_fuzzy), 'i');
  re.host_fuzzy_test  = RegExp(untpl(re.tpl_host_fuzzy_test), 'i');

  //
  // Compile each schema
  //

  var aliases = [];

  self.__compiled__ = {}; // Reset compiled data

  function schemaError(name, val) {
    throw new Error('(LinkifyIt) Invalid schema "' + name + '": ' + val);
  }

  Object.keys(self.__schemas__).forEach(function (name) {
    var val = self.__schemas__[name];

    // skip disabled methods
    if (val === null) { return; }

    var compiled = { validate: null, link: null };

    self.__compiled__[name] = compiled;

    if (isObject(val)) {
      if (isRegExp(val.validate)) {
        compiled.validate = createValidator(val.validate);
      } else if (isFunction(val.validate)) {
        compiled.validate = val.validate;
      } else {
        schemaError(name, val);
      }

      if (isFunction(val.normalize)) {
        compiled.normalize = val.normalize;
      } else if (!val.normalize) {
        compiled.normalize = createNormalizer();
      } else {
        schemaError(name, val);
      }

      return;
    }

    if (isString(val)) {
      aliases.push(name);
      return;
    }

    schemaError(name, val);
  });

  //
  // Compile postponed aliases
  //

  aliases.forEach(function (alias) {
    if (!self.__compiled__[self.__schemas__[alias]]) {
      // Silently fail on missed schemas to avoid errons on disable.
      // schemaError(alias, self.__schemas__[alias]);
      return;
    }

    self.__compiled__[alias].validate =
      self.__compiled__[self.__schemas__[alias]].validate;
    self.__compiled__[alias].normalize =
      self.__compiled__[self.__schemas__[alias]].normalize;
  });

  //
  // Fake record for guessed links
  //
  self.__compiled__[''] = { validate: null, normalize: createNormalizer() };

  //
  // Build schema condition
  //
  var slist = Object.keys(self.__compiled__)
                      .filter(function (name) {
                        // Filter disabled & fake schemas
                        return name.length > 0 && self.__compiled__[name];
                      })
                      .map(escapeRE)
                      .join('|');
  // (?!_) cause 1.5x slowdown
  self.re.schema_test   = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'i');
  self.re.schema_search = RegExp('(^|(?!_)(?:[><\uff5c]|' + re.src_ZPCc + '))(' + slist + ')', 'ig');

  self.re.pretest = RegExp(
    '(' + self.re.schema_test.source + ')|(' + self.re.host_fuzzy_test.source + ')|@',
    'i'
  );

  //
  // Cleanup
  //

  resetScanCache(self);
}
54107
public static String formatCompiledPattern(String compiledPattern, CharSequence... values) {
        return formatAndAppend(compiledPattern, new StringBuilder(), null, values).toString();
    }
1340462
private URLPatternHolder convertStringToPattern(String line) {
        URLPatternHolder holder = new URLPatternHolder();
        Pattern compiledPattern;
        Perl5Compiler compiler = new Perl5Compiler();
        String perl5RegExp = line;
        try {
            compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
            holder.setCompiledPattern(compiledPattern);
        } catch (MalformedPatternException mpe) {
            throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
        }
        return holder;
    }
1138738
function getOrCompile (patternStr) {
    var tree, fn;
    if (!patterns.hasOwnProperty(patternStr)) {
      tree = parse(patternStr);
      if (!normalized.hasOwnProperty(tree.pattern)) {
        fn = compile(tree);
        fn.pattern = tree.pattern;
        normalized[tree.pattern] = fn;
      }
      patterns[patternStr] = normalized[tree.pattern];
    }
    return patterns[patternStr];
  }
1209947
static List<String> parsePattern(String pattern) {
    List<String> parameters = new ArrayList<>(4);
    Matcher matcher = PARAM_REGEX.matcher(pattern);
    while (matcher.find()) {
      parameters.add(matcher.group(1));
    }
    return parameters;
  }
718761
private static String convertPattern(ProxyRule bean) {
        String str = bean.getPattern().replaceAll("\\{.+?\\}", "([^/&?]*)"); // /foo/{bar}/{baz} => /foo/([^\/&?]*)/([^/&?]*).*
        return str.endsWith("$") ? str : str + ".*";  // Implicitly other stuff on end unless $ explicitly specified (see description)
    }
696481
public void compile(String pattern) {
		this.expandedPattern = expand(pattern);
		
		// Compile the regex
		if (!expandedPattern.isEmpty()) {
			regexp = Pattern.compile(expandedPattern);
		} else {
			throw new IllegalArgumentException("Pattern is not found '"
					+ pattern + "'");
		}
	}
81646
private static String adopt2JavaPattern(String pattern)
   {
      pattern = normalizePath(pattern);

      // any character except '/', one or more times
      pattern = pattern.replaceAll("\\" + ANY_NAME, "[^/]+");

      // any character except '/' exactly one time
      pattern = pattern.replaceAll(ANY_CHAR, "[^/]{1}");

      return pattern;
   }
1058727
protected Pattern[] queryDetectionPattern(final Pattern... pattern) {
        if (pattern == null) {
            throw new IllegalArgumentException();
        } // end of if

        // ---

        if (this.queryDetection == null) {
            return pattern;
        } // end of if

        // ---

        final Pattern[] patterns = 
            new Pattern[this.queryDetection.length + pattern.length];

        System.arraycopy(this.queryDetection, 0, 
                         patterns, 0, 
                         this.queryDetection.length);

        int i = this.queryDetection.length;

        for (final Pattern p : pattern) {
            patterns[i++] = p;
        } // end of for

        return patterns;
    }