construct a regex that matches possible fields in a transformed file
    annotations is a set of which keys in BARCODEINFO are present in the file
500016
def construct_transformed_regex(annotations):
    
    re_string = '.*'
    if "cellular" in annotations:
        re_string += ":CELL_(?P<CB>.*)"
    if "molecular" in annotations:
        re_string += ":UMI_(?P<MB>\w*)"
    if "sample" in annotations:
        re_string += ":SAMPLE_(?P<SB>\w*)"
    if re_string == ".*":
        logger.error("No annotation present on this file, aborting.")
        sys.exit(1)
    return re_string
423500
def regex(name, regexp, options = {})
      field name, RegexField.new(regexp, options)
    end
630917
def get_function_annotations(event, funcname, type=None, namespace=None):
    """"""
    if type:
        postfix = "|" + type
    else:
        postfix = "|.+"

    def matchfunc(key, annkey):
        """Check if the provider regex matches an annotation key."""
        return re.match(key, annkey) is not None

    return get_annotations(event, funcname + postfix, namespace=namespace,
                           matchfunc=matchfunc)
902536
def extract_keypairs(lines, regexer):
    """"""
    updates = {}
    for line in lines:
        # for consistency we must match the replacer and strip whitespace / newlines
        match = regexer.match(line.strip())
        if not match:
            continue
        k_v = match.groupdict()
        updates[k_v[Constants.KEY_GROUP]] = k_v[Constants.VALUE_GROUP]
    return updates
1210826
private void extractAnnotation() {
		for (Class<? extends IFile> clazz : LISTE_CLASS) {

			Map<ITag, AnnotationData> maps = new HashMap<ITag, AnnotationData>();
			Set<AnnotationData> set = new TreeSet<AnnotationData>();

			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				AnnotationData param = new AnnotationData();
				field.setAccessible(true);
				param.setField(field);
				Data annotation = field.getAnnotation(Data.class);
				if (annotation != null) {
					param.initFromAnnotation(annotation);
					maps.put(param.getTag(), param);
					try {
						set.add((AnnotationData) param.clone());
					} catch (CloneNotSupportedException e) {
						// do nothing
					}
				}
			}
			mapSet.put(clazz.getName(), set);
			map.put(clazz.getName(), maps);
		}
	}
373342
function generateNamedFieldExtractors(input) {
  var names = input.filter(function(matcher, index, array) {
    // has a name?
    return matcher.name;
  });
  // has duplicates?
  names.forEach(function(matcher, index, array) {
    var isDuplicate = array.slice(0, index).some(function(previousMatcher) {
      return previousMatcher.name == matcher.name;
    });
    if (isDuplicate) {
      throw new Error("duplicate named field '" + matcher.name + "'");
    }
  });
  return names;
}
1168463
def fnmatch_pathname_to_regex(pattern):
	
	i, n = 0, len(pattern)
	nonsep = ''.join(['[^', os.sep, ']'])
	res = []
	while i < n:
		c = pattern[i]
		i = i + 1
		if c == '*':
			try:
				if pattern[i] == '*':
					i = i + 1
					res.append('.*')
					if pattern[i] == '/':
						i = i + 1
						res.append(''.join([os.sep, '?']))
				else:
					res.append(''.join([nonsep, '*']))
			except IndexError:
				res.append(''.join([nonsep, '*']))
		elif c == '?':
			res.append(nonsep)
		elif c == '/':
			res.append(os.sep)
		elif c == '[':
			j = i
			if j < n and pattern[j] == '!':
				j = j + 1
			if j < n and pattern[j] == ']':
				j = j + 1
			while j < n and pattern[j] != ']':
				j = j+1
			if j >= n:
				res.append('\\[')
			else:
				stuff = pattern[i:j].replace('\\', '\\\\')
				i = j+1
				if stuff[0] == '!':
					stuff = ''.join('^', stuff[1:])
				elif stuff[0] == '^':
					stuff = ''.join('\\' + stuff)
				res.append('[{}]'.format(stuff))
		else:
			res.append(re.escape(c))
	res.insert(0, '(?ms)')
	res.append('\Z')
	return ''.join(res)
748438
def file_matches_regexps(filename, patterns):
    """"""
    return any(re.match(pat, filename) for pat in patterns)
101403
public static Annotation[] findAnnotations(AbstractVariableDeclaration field, Pattern namePattern) {
		List<Annotation> result = new ArrayList<Annotation>();
		if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
		for (Annotation annotation : field.annotations) {
			TypeReference typeRef = annotation.type;
			if (typeRef != null && typeRef.getTypeName() != null) {
				char[][] typeName = typeRef.getTypeName();
				String suspect = new String(typeName[typeName.length - 1]);
				if (namePattern.matcher(suspect).matches()) {
					result.add(annotation);
				}
			}
		}	
		return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
	}
784990
def regex_in_file(regex, filepath, return_match=False):
    
    file_content = get_file_content(filepath)
    re_method = funcy.re_find if return_match else funcy.re_test
    return re_method(regex, file_content)
167927
function extractBinaryFields(target, spec, data) {
  var offset = 0;

  for (var x = 0; x < spec.length; x++) {
    var item = spec[x];
    if (item.label) {
      if (item.type === 'string') {
        var bytes = new DataView(data.buffer, offset, item.size);
        var str = textDecoder.decode(bytes);
        target[item.label] = str.replace(/\0/g, '');
      } else {
        target[item.label] = data['get' + item.type + (item.size * 8)](offset);
      }
    }
    offset += item.size;
  }

  return offset;
}
817581
def _make_regex(pem_type):
    '''
    
    '''
    return re.compile(
        r"\s*(?P<pem_header>-----BEGIN {0}-----)\s+"
        r"(?:(?P<proc_type>Proc-Type: 4,ENCRYPTED)\s*)?"
        r"(?:(?P<dek_info>DEK-Info: (?:DES-[3A-Z\-]+,[0-9A-F]{{16}}|[0-9A-Z\-]+,[0-9A-F]{{32}}))\s*)?"
        r"(?P<pem_body>.+?)\s+(?P<pem_footer>"
        r"-----END {0}-----)\s*".format(pem_type),
        re.DOTALL
    )
721387
def extract_annotations_from(file, pattern)
      lineno = 0
      result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
        lineno += 1
        next list unless line =~ pattern
        list << Annotation.new(lineno, $1, $2)
      end
      result.empty? ? {} : { file => result }
    end
953878
def extract_object_names_from_docs(filename):
    """"""
    text = split_code_and_text_blocks(filename)[1]
    text = '\n'.join(t[1] for t in text if t[0] == 'text')
    regex = re.compile(r':(?:'
                       r'func(?:tion)?|'
                       r'meth(?:od)?|'
                       r'attr(?:ibute)?|'
                       r'obj(?:ect)?|'
                       r'class):`(\S*)`'
                       )
    return [(x, x) for x in re.findall(regex, text)]
441513
public String[] generateTypeMismatchCodes(final String objectName, final String field, final Class<?> fileType) {
        return generateCodes(getTypeMismatchCode(), objectName, field, fileType);
    }
298985
def str_matcher(mode):
    

    def f_raw(inp_str, pos):
        return unique_literal_cache_pool[mode] if inp_str.startswith(mode, pos) else None

    def f_collection(inp_str, pos):
        for each in mode:
            if inp_str.startswith(each, pos):
                return unique_literal_cache_pool[each]
        return None

    if isinstance(mode, str):
        return f_raw

    if len(mode) is 1:
        mode = mode[0]
        return f_raw

    return f_collection
800242
def _set_annotation_to_str(annotation_data: Mapping[str, Mapping[str, bool]], key: str) -> str:
    """"""
    value = annotation_data[key]

    if len(value) == 1:
        return 'SET {} = "{}"'.format(key, list(value)[0])

    x = ('"{}"'.format(v) for v in sorted(value))

    return 'SET {} = {{{}}}'.format(key, ', '.join(x))