Creates a regular expression to use for matching delimiters, based on
the given options.
427494
function createDelimiterRegex(options) {
  const opts = Object.assign({}, options);
  let tagname = options.tagname;
  let layoutDelims = options.delims || options.layoutDelims || `{% (${tagname}) %}`;
  let key = tagname;

  if (layoutDelims) key += layoutDelims.toString();
  if (layouts.memo.has(key)) {
    return layouts.memo.get(key);
  }

  if (layoutDelims instanceof RegExp) {
    layouts.memo.set(key, layoutDelims);
    return layoutDelims;
  }

  if (Array.isArray(layoutDelims)) {
    layoutDelims = `${opts.layoutDelims[0]} (${tagname}) ${opts.layoutDelims[1]}`;
  }

  if (typeof layoutDelims !== 'string') {
    throw new TypeError('expected options.layoutDelims to be a string, array or regex');
  }

  const regex = new RegExp(layoutDelims, 'g');
  layouts.memo.set(key, regex);
  return regex;
}
1129260
function tokensToRegExp (tokens, keys, options) {
  if (!isarray(keys)) {
    options = /** @type {!Object} */ (keys || options);
    keys = [];
  }

  options = options || {};

  var strict = options.strict;
  var end = options.end !== false;
  var route = '';

  // Iterate over the tokens and create our regexp string.
  for (var i = 0; i < tokens.length; i++) {
    var token = tokens[i];

    if (typeof token === 'string') {
      route += escapeString(token);
    } else {
      var prefix = escapeString(token.prefix);
      var capture = '(?:' + token.pattern + ')';

      keys.push(token);

      if (token.repeat) {
        capture += '(?:' + prefix + capture + ')*';
      }

      if (token.optional) {
        if (!token.partial) {
          capture = '(?:' + prefix + '(' + capture + '))?';
        } else {
          capture = prefix + '(' + capture + ')?';
        }
      } else {
        capture = prefix + '(' + capture + ')';
      }

      route += capture;
    }
  }

  var delimiter = escapeString(options.delimiter || '/');
  var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;

  // In non-strict mode we allow a slash at the end of match. If the path to
  // match already ends with a slash, we remove it for consistency. The slash
  // is valid at the end of a path match, not in the middle. This is important
  // in non-ending mode, where "/test/" shouldn't match "/test//route".
  if (!strict) {
    route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
  }

  if (end) {
    route += '$';
  } else {
    // In non-ending mode, we need the capturing groups to match as much as
    // possible by using a positive lookahead to the end or next path segment.
    route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
  }

  return attachKeys(new RegExp('^' + route, flags(options)), keys)
}
315771
public static boolean validateOptionalField(String field, String reg) {
        if (field == null || field.isEmpty()) {
            return true;
        }
        return Pattern.matches(reg, field);
    }
752745
def _split_regex(regex):
    
    if regex[0] == '^':
        regex = regex[1:]
    if regex[-1] == '$':
        regex = regex[0:-1]
    results = []
    line = ''
    for c in regex:
        if c == '(':
            results.append(line)
            line = ''
        elif c == ')':
            line = ''
        else:
            line = line + c
    if len(line) > 0:
        results.append(line)
    return results
775835
private static int extractOptions(String pattern, int i, List options) {
    while ((i < pattern.length()) && (pattern.charAt(i) == '{')) {
      int end = pattern.indexOf('}', i);

      if (end == -1) {
        break;
      }

      String r = pattern.substring(i + 1, end);
      options.add(r);
      i = end + 1;
    }

    return i;
  }
1172675
def make_regex(separator):
    
    return re.compile(r'(?:' + re.escape(separator) + r')?((?:[^' +
                      re.escape(separator) + r'\\]|\\.)+)')
133909
public RegexMatcher addExpression(String expr, T attach, Option... options)
    {
        if (nfa == null)
        {
            nfa = parser.createNFA(nfaScope, expr, attach, options);
        }
        else
        {
            NFA<T> nfa2 = parser.createNFA(nfaScope, expr, attach, options);
            nfa = new NFA<>(nfaScope, nfa, nfa2);
        }
        return this;
    }
1191782
public static String concatStringWithDelimiter(String[] strings, String delimiter) {
        StringBuilder sbr = new StringBuilder();
        int size = strings.length;
        for (int i = 0; i < size - 1; i++) {
            sbr.append(strings[i]).append(delimiter);
        }
        sbr.append(strings[size - 1]);
        return sbr.toString();
    }
1186032
public PactDslJsonArray stringMatcher(String regex, String value) {
        if (!value.matches(regex)) {
            throw new InvalidMatcherException(EXAMPLE + value + "\" does not match regular expression \"" +
                regex + "\"");
        }
        body.put(value);
        matchers.addRule(rootPath + appendArrayIndex(0), regexp(regex));
        return this;
    }
825534
function matchArray(value, pattern, options) {
  if (!(value instanceof Array)) {
    return false;
  }
  if (!options.matchPartialArrays && pattern.length !== value.length) {
    return false;
  }
  if (pattern.length > value.length) {
    return false;
  }
  if (options.matchOutOfOrderArrays) {
    return pattern.every(
      (nestedMatch) => value.some(
        (nestedValue) => matchr(nestedValue, nestedMatch, options)
      )
    );
  }
  let valueIndex = 0;
  for (const nestedMatcher of pattern) {
    while (valueIndex < value.length && !matchr(value[valueIndex], nestedMatcher, options)) {
      valueIndex++;
    }
    if (valueIndex === value.length) {
      return false;
    }
  }
  return true;
}
150581
protected static Pattern makePattern (String input)
    {
        StringBuilder pattern = new StringBuilder('^');

        while (true) {
            String[] parts = _splitter.split(input, 2);
            pattern.append(Pattern.quote(parts[0]));
            if (parts.length == 1) {
                break;
            }
            int length = parts[0].length();
            String wildcard = input.substring(length, length + 1);
            if (wildcard.equals("*")) {
                pattern.append(".*");
            } else {
                System.err.println("Bad wildcard " + wildcard);
            }
            input = parts[1];
        }

        pattern.append("$");
        return Pattern.compile(pattern.toString());
    }
1112479
def regexp_prompt(prompt, regexp='.', answer=''):
    '''
    
    '''
    get_input = getattr(__builtins__, 'raw_input', input)
    while not re.search(regexp, answer):
        answer = get_input(prompt + ': ').strip()
        # If the option isn't valid, this is shown next
        message = "Your entry must match the regular expression %s" %regexp    

    return answer
1108805
def _encode_regex(name, value, dummy0, dummy1):
    """"""
    flags = value.flags
    # Python 2 common case
    if flags == 0:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"\x00"
    # Python 3 common case
    elif flags == re.UNICODE:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"u\x00"
    else:
        sflags = b""
        if flags & re.IGNORECASE:
            sflags += b"i"
        if flags & re.LOCALE:
            sflags += b"l"
        if flags & re.MULTILINE:
            sflags += b"m"
        if flags & re.DOTALL:
            sflags += b"s"
        if flags & re.UNICODE:
            sflags += b"u"
        if flags & re.VERBOSE:
            sflags += b"x"
        sflags += b"\x00"
        return b"\x0B" + name + _make_c_string_check(value.pattern) + sflags
835956
function getRegex(regex, flags) {
  var result = typeOf(regex) === 'String'
    ? new RegExp(regex, flags || '')
    : regex

  if (typeOf(result) !== 'RegExp') {
    throw new Error(
      NAME + ': option "regex" must be a string or a RegExp object')
  }

  return result
}
598241
function (filename, types) {
    types = types.split(',');
    var pattern = '\.(';
    for (var i = 0; i < types.length; i++) {
        if (0 != i) {
            pattern += '|';
        }
        pattern += types[i].trim();
    }
    pattern += ')$';
    return new RegExp(pattern, 'i').test(filename);
}
1335326
def _construct_regex(cls, fmt):
        """"""
        return re.compile(fmt.format(**vars(cls)), flags=re.U)
9315
static Matcher combineCharSeqAfterIndexOf(Matcher matcher) {
    if (matcher instanceof IndexOfMatcher) {
      IndexOfMatcher m = matcher.as();
      Matcher next = PatternUtils.head(m.next());
      if (next instanceof CharSeqMatcher) {
        String pattern = m.pattern() + next.<CharSeqMatcher>as().pattern();
        return new IndexOfMatcher(pattern, PatternUtils.tail(m.next()));
      }
    }
    return matcher;
  }