Make an attempt at converting a format spec to a regular expression.
192950
def format_spec_to_regex(field_name, format_spec):
        """"""
        # NOTE: remove escaped backslashes so regex matches
        regex_match = fmt_spec_regex.match(format_spec.replace('\\', ''))
        if regex_match is None:
            raise ValueError("Invalid format specification: '{}'".format(format_spec))
        regex_dict = regex_match.groupdict()
        fill = regex_dict['fill']
        ftype = regex_dict['type']
        width = regex_dict['width']
        align = regex_dict['align']
        # NOTE: does not properly handle `=` alignment
        if fill is None:
            if width is not None and width[0] == '0':
                fill = '0'
            elif ftype in ['s', 'd']:
                fill = ' '

        char_type = spec_regexes[ftype]
        if ftype == 's' and align and align.endswith('='):
            raise ValueError("Invalid format specification: '{}'".format(format_spec))
        final_regex = char_type
        if ftype in allow_multiple and (not width or width == '0'):
            final_regex += r'*'
        elif width and width != '0':
            if not fill:
                # we know we have exactly this many characters
                final_regex += r'{{{}}}'.format(int(width))
            elif fill:
                # we don't know how many fill characters we have compared to
                # field characters so just match all characters and sort it out
                # later during type conversion.
                final_regex = r'.{{{}}}'.format(int(width))
            elif ftype in allow_multiple:
                final_regex += r'*'

        return r'(?P<{}>{})'.format(field_name, final_regex)
249024
function format(string, args) {
    if (
        string.length === 0 ||
        !args ||
        Object.keys(args).length === 0
    ) {
        return string;
    }
    var matchVar = '[0-9a-zA-Z_$\\.]+',
        matchBrackets = '\\[[^\\]]*\\]',
        matchParsing = new RegExp(
            //"^" +
            "((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path
            "(!([rsa]))?" + //Conversion
            "(:([^\\?\\!]+))?" //spec
            //"$"
        ),
        matchCount = 0;

    return string.replace(FORMAT_EXPRESSION, function (_, match) {
        var parts = match.match(matchParsing),
            argName = parts[1] || matchCount,
            conversion = parts[4] || 's', //Default is string conversion
            formatSpec = parts[6],
            value = formatArgGet(args, argName);

        matchCount += 1;
        if (value === undefined) {
            return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP;//Replace unchanged
        }

        if (formatSpec && formatSpec.length > 0) {
            value = formatValueSpec(value, formatSpec);
        }

        //Conversion s, r or a
        switch (conversion) {
        case 's':
            return '' + value;
        case 'r':
            return inspect(value);
        case 'a':
            throw new Error('Not yet implemented conversion "' + conversion + '"');
        default:
            throw new Error('Invalid conversion "' + conversion + '"');
        }


    });
}
515698
def regexpr_validator(value):
    
    try:
        re.compile(value)
    except re.error:
        raise ValidationError(
            _('"%(value)s" is not a valid regular expression'),
            params={'value': value}
        )
1271809
def _match(self, regex):
        """"""
        cregex = re.compile(regex)
        for line in self.content.splitlines():
            match = cregex.match(line)
            if match:
                return match
        raise Exception('No "{0}" line in {1}.cpp'.format(
            regex_to_error_msg(regex),
            self.name
        ))
147936
def _make_regex(self):
    
    return re.compile("|".join(map(re.escape, self.keys())))
1335326
def _construct_regex(cls, fmt):
        """"""
        return re.compile(fmt.format(**vars(cls)), flags=re.U)
160471
def _inject_format_spec(self, value, format_spec):
        
        t = type(value)
        return value[:-1] + t(u':') + format_spec + t(u'}')
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);
}
646280
def format_field_by_match(self, value, match):
        """"""
        groups = match.groups()
        fill, align, sign, sharp, zero, width, comma, prec, type_ = groups
        if not comma and not prec and type_ not in list('fF%'):
            return None
        if math.isnan(value) or math.isinf(value):
            return None
        locale = self.numeric_locale
        # Format number value.
        prefix = get_prefix(sign)
        if type_ == 'd':
            if prec is not None:
                raise ValueError('precision not allowed in '
                                 'integer format specifier')
            string = format_number(value, 0, prefix, locale)
        elif type_ in 'fF%':
            format_ = format_percent if type_ == '%' else format_number
            string = format_(value, int(prec or DEFAULT_PREC), prefix, locale)
        else:
            # Don't handle otherwise.
            return None
        if not comma:
            # Formatted number always contains group symbols.
            # Remove the symbols if not required.
            string = remove_group_symbols(string, locale)
        if not (fill or align or zero or width):
            return string
        # Fix a layout.
        spec = ''.join([fill or u'', align or u'>',
                        zero or u'', width or u''])
        return format(string, spec)
636788
def match(self, regexp, flags=None):
        """"""

        try:
            reg = _regexp_cache[(regexp, flags)]
        except KeyError:
            if flags:
                reg = re.compile(regexp, flags)
            else:
                reg = re.compile(regexp)
            _regexp_cache[(regexp, flags)] = reg

        return self.match_reg(reg)
874396
function asRegExp(pattern) {
  // if regex then return it
  if (isRegExp(pattern)) {
    return pattern;
  }

  // if string then test for valid regex then convert to regex and return
  const match = pattern.match(REGEX);
  if (match) {
    return new RegExp(match[1], match[2]);
  }

  return new RegExp(pattern);
}
860603
def format_field(self, value, format_spec):
        """"""
        if isinstance(value, MissingField):
            if format_spec is not None:
                value.format_spec = format_spec
            return str(value)

        return super(FormatterWrapper, self).format_field(value, format_spec)
1250610
def validate(self, value):
        
        if not self._compiled_regex.match(value):
            raise ValidationError(
                'value {:s} not match r"{:s}"'.format(value, self._regex))
773479
def regexpExec(self, content):
        
        ret = libxml2mod.xmlRegexpExec(self._o, content)
        return ret
704658
def _regex_from_encoded_pattern(s):
    """'
    """
    if s.startswith('/') and s.rfind('/') != 0:
        # Parse it: /PATTERN/FLAGS
        idx = s.rfind('/')
        pattern, flags_str = s[1:idx], s[idx+1:]
        flag_from_char = {
            "i": re.IGNORECASE,
            "l": re.LOCALE,
            "s": re.DOTALL,
            "m": re.MULTILINE,
            "u": re.UNICODE,
        }
        flags = 0
        for char in flags_str:
            try:
                flags |= flag_from_char[char]
            except KeyError:
                raise ValueError("unsupported regex flag: '%s' in '%s' "
                                 "(must be one of '%s')"
                                 % (char, s, ''.join(list(flag_from_char.keys()))))
        return re.compile(s[1:idx], flags)
    else: # not an encoded regex
        return re.compile(re.escape(s))
1241343
def get_precision_regex():
    """"""
    expr = re.escape(PRECISION_FORMULA)
    expr += r'=\s*(\S*)\s.*\s([A-Z]*)'
    return re.compile(expr)
529731
def match(pattern):
    
    regex = re.compile(pattern)

    def validate(value):
        if not regex.match(value):
            return e("{} does not match the pattern {}", value, pattern)
    return validate