The list of patterns can contain either strings or compiled regular
        expressions.
434436
def _assert_matches_re(self, field, expected_patterns):
        
        value = getattr(self, field)
        for pattern in expected_patterns:
            try:
                if pattern.match(value):
                    return
            except AttributeError:
                # It's not a compiled regex, treat it as string.
                if re.match(pattern, value):
                    return
        raise ValueError("%s: Field '%s' has invalid value: %s. It does not match any provided REs: %s"
                         % (self.__class__.__name__, field, value, expected_patterns))
1346395
public static final boolean isListItem(String pattern)
    {
        int idx = pattern.lastIndexOf(Lim);
        if (idx != -1)
        {
            try
            {
                Integer.parseInt(pattern.substring(idx+1));
                return true;
            }
            catch (NumberFormatException ex)
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
966957
def prettyMatcherList(things):
    """"""
    norm = []
    for x in makeSequence(things):
        if hasattr(x, 'pattern'):
            norm.append(x.pattern)
        else:
            norm.append(x)
    return "('%s')" % "', '".join(norm)
1298370
def fnmatches(entry, *pattern_list):
    

    for pattern in pattern_list:
        if pattern and fnmatch(entry, pattern):
            return True
    return False
1102241
def findall(self, string):
        
        output = []
        for match in self.pattern.findall(string):
            if hasattr(match, 'strip'):
                match = [match]
            self._list_add(output, self.run(match))
        return output
250239
def _get_searchable_regex(basic=None, hidden=None):
    """"""
    # Hidden labels are used to store regular expressions.
    basic = basic or []
    hidden = hidden or []

    hidden_regex_dict = {}
    for hidden_label in hidden:
        if _is_regex(hidden_label):
            hidden_regex_dict[hidden_label] = \
                re.compile(
                    current_app.config["CLASSIFIER_WORD_WRAP"]
                    % hidden_label[1:-1]
            )
        else:
            pattern = _get_regex_pattern(hidden_label)
            hidden_regex_dict[hidden_label] = re.compile(
                current_app.config["CLASSIFIER_WORD_WRAP"] % pattern
            )

    # We check if the basic label (preferred or alternative) is matched
    # by a hidden label regex. If yes, discard it.
    regex_dict = {}
    # Create regex for plural forms and add them to the hidden labels.
    for label in basic:
        pattern = _get_regex_pattern(label)
        regex_dict[label] = re.compile(
            current_app.config["CLASSIFIER_WORD_WRAP"] % pattern
        )

    # Merge both dictionaries.
    regex_dict.update(hidden_regex_dict)

    return list(regex_dict.values())
76821
def _parse_known_pattern(self, pattern: str) -> List[str]:
        
        if pattern.endswith(os.path.sep):
            patterns = [
                filename
                for filename in os.listdir(pattern)
                if os.path.isdir(os.path.join(pattern, filename))
            ]
        else:
            patterns = [pattern]

        return patterns
926461
public List<String> findList(String str, String regex) {
		ArrayList<String> ret = new ArrayList<String>();
		if (str == null || regex == null)
			return ret;
		Matcher m = Pattern.compile(regex).matcher(str);
		while (m.find()) {
			ret.add(m.group());
		}
		return ret;
	}
1245863
def patterns(self):
        
        # No explicit argument for patterns ==> consider the first source argument as pattern.
        if not self.args.patterns and not self.args.pattern_files:
            try:
                self.args.patterns.append(self.args.files.pop(0))
            except IndexError:
                raise LogRaptorArgumentError('PATTERN', 'no search pattern')

        # Get the patterns from arguments and files
        patterns = set()
        if self.args.pattern_files:
            patterns.update([p.rstrip('\n') for p in fileinput.input(self.args.pattern_files)])
        patterns.update(self.args.patterns)
        logger.debug("search patterns to be processed: %r", patterns)

        # If one pattern is empty then skip the other patterns
        if '' in patterns:
            logger.info("an empty pattern provided: match all strings!")
            return tuple()

        try:
            flags = re.IGNORECASE if self.args.case else 0 | re.UNICODE
            return tuple([
                re.compile(r'(\b%s\b)' % pat if self.args.word else '(%s)' % pat, flags=flags)
                for pat in patterns if pat
            ])
        except re.error as err:
            raise LogRaptorArgumentError('wrong regex syntax for pattern: %r' % err)
418649
def _generate_regex(self, line):
        '''
        
        '''
        restr = ""

        # Strings and single byte signatures are taken at face value;
        # multi-byte integer values are turned into regex strings based
        # on their data type size and endianness.
        if line.type == 'regex':
            # Regex types are already compiled expressions.
            # Note that since re.finditer is used, unless the specified
            # regex accounts for it, overlapping signatures will be ignored.
            return line.value
        if line.type == 'string':
            restr = line.value
        elif line.size == 1:
            restr = chr(line.value)
        elif line.size == 2:
            if line.endianness == '<':
                restr = chr(line.value & 0xFF) + chr(line.value >> 8)
            elif line.endianness == '>':
                restr = chr(line.value >> 8) + chr(line.value & 0xFF)
        elif line.size == 4:
            if line.endianness == '<':
                restr = (chr(line.value & 0xFF) +
                         chr((line.value >> 8) & 0xFF) +
                         chr((line.value >> 16) & 0xFF) +
                         chr(line.value >> 24))
            elif line.endianness == '>':
                restr = (chr(line.value >> 24) +
                         chr((line.value >> 16) & 0xFF) +
                         chr((line.value >> 8) & 0xFF) +
                         chr(line.value & 0xFF))
        elif line.size == 8:
            if line.endianness == '<':
                restr = (chr(line.value & 0xFF) +
                         chr((line.value >> 8) & 0xFF) +
                         chr((line.value >> 16) & 0xFF) +
                         chr((line.value >> 24) & 0xFF) +
                         chr((line.value >> 32) & 0xFF) +
                         chr((line.value >> 40) & 0xFF) +
                         chr((line.value >> 48) & 0xFF) +
                         chr(line.value >> 56))
            elif line.endianness == '>':
                restr = (chr(line.value >> 56) +
                         chr((line.value >> 48) & 0xFF) +
                         chr((line.value >> 40) & 0xFF) +
                         chr((line.value >> 32) & 0xFF) +
                         chr((line.value >> 24) & 0xFF) +
                         chr((line.value >> 16) & 0xFF) +
                         chr((line.value >> 8) & 0xFF) +
                         chr(line.value & 0xFF))

        # Since re.finditer is used on a per-signature basis, signatures should be crafted carefully
        # to ensure that they aren't potentially self-overlapping (e.g., a signature of "ABCDAB" could
        # be confused by the byte sequence "ABCDABCDAB"). The longer the signature, the less likely an
        # unintentional overlap is, although files could still be maliciously crafted to cause false
        # negative results.
        #
        # Thus, unless a signature has been explicitly marked as knowingly overlapping ('{overlap}'),
        # spit out a warning about any self-overlapping signatures.
        if not binwalk.core.compat.has_key(line.tags, 'overlap'):
            for i in range(1, line.size):
                if restr[i:] == restr[0:(line.size - i)]:
                    binwalk.core.common.warning("Signature '%s' is a self-overlapping signature!" % line.text)
                    break

        return re.compile(re.escape(restr))
656322
public boolean checkRegexPattern(final Optional<Subject> subjectOption,
                                     final Optional<Pattern> patternOption)
    {
        final boolean[] roleOk = {false};
        subjectOption.ifPresent(subject -> patternOption.ifPresent(pattern -> {
            final List<? extends Permission> permissions = subject.getPermissions();
            if (permissions != null)
            {
                for (Iterator<? extends Permission> iterator = permissions.iterator(); !roleOk[0] && iterator.hasNext(); )
                {
                    final Permission permission = iterator.next();
                    roleOk[0] = pattern.matcher(permission.getValue()).matches();
                }
            }
        }));

        return roleOk[0];
    }
748438
def file_matches_regexps(filename, patterns):
    """"""
    return any(re.match(pat, filename) for pat in patterns)
1311444
static boolean containsMatch(String actual, String regex) {
    return Pattern.compile(regex).matcher(actual).find();
  }
637896
def re_filter(text, regexps):
    """"""
    if not regexps:
        return text

    matched_text = []
    compiled_regexps = [re.compile(x) for x in regexps]
    for line in text:
        if line in matched_text:
            continue

        for regexp in compiled_regexps:
            found = regexp.search(line)
            if found and found.group():
                matched_text.append(line)

    return matched_text or text
767865
public static boolean matches(String pattern, String value) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(value);
        return m.matches();
    }
1028727
function matchPatternOrExact(patternStrings, candidate) {
        var patterns = [];
        for (var _i = 0, patternStrings_1 = patternStrings; _i < patternStrings_1.length; _i++) {
            var patternString = patternStrings_1[_i];
            var pattern = tryParsePattern(patternString);
            if (pattern) {
                patterns.push(pattern);
            }
            else if (patternString === candidate) {
                // pattern was matched as is - no need to search further
                return patternString;
            }
        }
        return findBestPatternMatch(patterns, function (_) { return _; }, candidate);
    }
734188
public static String restrictHTML (String src, String[] regexes)
    {
        if (StringUtil.isBlank(src)) {
            return src;
        }

        ArrayList<String> list = new ArrayList<String>();
        list.add(src);
        for (String regexe : regexes) {
            Pattern p = Pattern.compile(regexe, Pattern.CASE_INSENSITIVE);
            for (int jj=0; jj < list.size(); jj += 2) {
                String piece = list.get(jj);
                Matcher m = p.matcher(piece);
                if (m.find()) {
                    list.set(jj, piece.substring(0, m.start()));
                    list.add(jj + 1, piece.substring(m.start(), m.end()));
                    list.add(jj + 2, piece.substring(m.end()));
                }
            }
        }

        // now, the even elements of list contain untrusted text, the
        // odd elements contain stuff that matched a regex
        StringBuilder buf = new StringBuilder();
        for (int jj=0, nn = list.size(); jj < nn; jj++) {
            String s = list.get(jj);
            if (jj % 2 == 0) {
                s = s.replace("<", "&lt;");
                s = s.replace(">", "&gt;");
            }
            buf.append(s);
        }
        return buf.toString();
    }