Return a regular expression with named groups for each wildcard.
513939
def _compile_pattern(self, rule):
        '''  '''
        out = ''
        for i, part in enumerate(self.syntax.split(rule)):
            if i%3 == 0:   out += re.escape(part.replace('\\:',':'))
            elif i%3 == 1: out += '(?P<%s>' % part if part else '(?:'
            else:          out += '%s)' % (part or '[^/]+')
        return re.compile('^%s$'%out)
644220
def _filter_by_regex(self, regex, text, group=1):
        """"""
        match = re.search(
            regex,
            text,
            re.MULTILINE
        )

        return match.group(group).strip() if (
            match and match.groups()
        ) else text
1001332
def re_keys(self, pattern):
        
        if not pattern.endswith("$"):
            pattern += "$"
        expr = re.compile(pattern)
        return list(filter(expr.match, self.keys()))
624848
def grep_param_names(self, regexp):
        
        if not isinstance(regexp, _pattern_type): regexp = compile(regexp)
        found_params = []
        def visit(innerself, regexp):
            if (innerself is not self) and regexp.match(innerself.hierarchy_name().partition('.')[2]):
                found_params.append(innerself)
        self.traverse(visit, regexp)
        return found_params
1175289
def _reExec(regex, string):
    ''''''
    m = regex.search(string)
    if not m: return None
    return [m.group()] + list(m.groups())
1200113
def is_wildcard(self):
        """"""
        _, token = self.token_next_by(t=T.Wildcard)
        return token is not None
993604
static function wildcardToRegexp( $wildcard, $separatorCharacter = false )
    {
        if ( !$separatorCharacter )
            $separatorCharacter = '#';
        $wildcardArray = preg_split( "#[*]#", $wildcard, -1, PREG_SPLIT_DELIM_CAPTURE );
        $wildcardList = array();
        $i = 0;
        foreach ( $wildcardArray as $wildcardElement )
        {
            if ( ( $i % 2 ) == 1 )
                $wildcardList[] = '(.+)';
            else
                $wildcardList[] = preg_quote( $wildcardElement, $separatorCharacter );
            ++$i;
        }
        $wildcardString = implode( '', $wildcardList );
        return $wildcardString;
    }
726920
def subgroup(self, t, i):
        """"""

        # (?flags)
        flags = self.get_flags(i, self.version == _regex.V0)
        if flags:
            self.flags(flags[2:-1])
            return [flags]

        # (?#comment)
        comments = self.get_comments(i)
        if comments:
            return [comments]

        verbose = self.verbose

        # (?flags:pattern)
        flags = self.get_flags(i, (self.version == _regex.V0), True)
        if flags:
            t = flags
            self.flags(flags[2:-1], scoped=True)

        current = []
        try:
            while t != ')':
                if not current:
                    current.append(t)
                else:
                    current.extend(self.normal(t, i))

                t = next(i)
        except StopIteration:
            pass
        self.verbose = verbose

        if t == ")":
            current.append(t)
        return current
1219585
def match_subgroup(sequence, pattern):
    """"""

    for element in sequence:
        match = re.match(pattern, element)

        if match:
            yield match.groupdict()
1140622
protected static function matchRegexpCode( $wildcard )
    {
        $matchWilcard = $wildcard['source_url'];
        $matchWilcardList = explode( "*", $matchWilcard );
        $regexpList = array();
        foreach ( $matchWilcardList as $matchWilcardItem )
        {
            $regexpList[] = preg_quote( $matchWilcardItem, '#' );
        }
        $matchRegexp = implode( '(.*)', $regexpList );

        return "#^$matchRegexp#i";
    }
76702
function wildCardMatch(text, pattern){
	var cards = pattern.split("*");
	if (!pattern.startsWith("*") && !text.startsWith(cards[0])) { //$NON-NLS-1$
		return false;
	}
	if (!pattern.endsWith("*") && !text.endsWith(cards[cards.length - 1])) { //$NON-NLS-1$
		return false;
	}
	return !cards.some(function(card){
		var idx = text.indexOf(card);
		if (idx === -1){
			return true;
		}
		text = text.substring(idx + card.length);
	});
}
1208202
function parsePattern(pattern) {
	var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
	// Treat consecutive wildcards as one (#12)
	var wildCardPattern = /\*+/g;
	var endOfLinePattern = /\\\$$/;

	pattern = normaliseEncoding(pattern)

	if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
		return pattern;
	}

	pattern = pattern
		.replace(regexSpecialChars, '\\$&')
		.replace(wildCardPattern, '(?:.*)')
		.replace(endOfLinePattern, '$');

	return new RegExp(pattern);
}
147936
def _make_regex(self):
    
    return re.compile("|".join(map(re.escape, self.keys())))
1065082
def build_groups(self, tokens):
        """"""
        groups = {}
        for token in tokens:
            match_type = MatchType.start if token.group_end else MatchType.single
            groups[token.group_start] = (token, match_type)
            if token.group_end:
                groups[token.group_end] = (token, MatchType.end)
        return groups
1335608
def group_re(self):
        '''  '''
        out = ''
        for token, data in self.tokens():
            if   token == 'TXT':  out += re.escape(data)
            elif token == 'VAR':  out += '(?P<%s>%s)' % (data[1], data[0])
            elif token == 'ANON': out += '(?:%s)' % data
        return out
751955
def FindRegex(self, regex, data):
    """"""
    for match in re.finditer(regex, data, flags=re.I | re.S | re.M):
      yield (match.start(), match.end())
602343
def filter_regex(names, regex):
    
    return tuple(name for name in names
                 if regex.search(name) is not None)