Helper method that returns a list of elements that match the
        given path pattern of form {type}.{group}.{label}.

        The input may be a Layout, an Overlay type or a single
        Element.
348237
def search(cls, element, pattern):
        
        if isinstance(element, Layout):
            return [el for cell in element for el in cls.search(cell, pattern)]
        if isinstance(element, (NdOverlay, Overlay)):
            return [el for el in element if el.matches(pattern)]
        elif isinstance(element, Element):
            return [element] if element.matches(pattern) else []
1217483
def match_patterns(pathname, patterns):
    """"""
    for pattern in patterns:
        if fnmatch(pathname, pattern):
            return True
    return False
210902
def list(self, relpattern):
        ""
        
        parent_path = os.path.dirname(relpattern)
        file_pattern = os.path.basename(relpattern)
        parent = self._resolve_path(parent_path)
        
        if parent is None:
            return []
        else:
            return [os.path.join(parent_path, name) 
                    for (name, mode, sha) in parent.iteritems() 
                    if fnmatch(name, file_pattern)]
493951
function PatternGroup(patterns) {

    this._pattern = l.map(patterns, function(expr) {
        return Pattern.toPattern(expr);
    });

}
819852
def _get_elements_property(parent_to_parse, element_path, prop_name):
    

    parent_element = get_element(parent_to_parse)

    if parent_element is None:
        return []

    if element_path and not element_exists(parent_element, element_path):
        return []

    if not element_path:
        texts = getattr(parent_element, prop_name)
        texts = texts.strip() if isinstance(texts, string_types) else texts
        texts = [texts] if texts else []
    else:
        texts = [t for t in (
            prop.strip() if isinstance(prop, string_types) else prop
            for prop in (getattr(node, prop_name) for node in parent_element.findall(element_path)) if prop
        ) if t]

    return texts
149481
def _list_files_in_path(path, pattern="*.stan"):
    

    results = []
    for dirname, subdirs, files in os.walk(path):
        for name in files:
            if fnmatch(name, pattern):
                results.append(os.path.join(dirname, name))
    return(results)
438481
public PatternElementMatch getLastLabeledMatch(String label) {
        PatternElementMatch cur = this;
        while (cur != null) {
            String elementLabel = cur.patternElement.getLabel();
            if (elementLabel != null && elementLabel.equals(label)) {
                return cur;
            }
            cur = cur.prev;
        }
        return null;
    }
372870
def match(self, path):
        ''''''
        match = self._regex.search(path)
        if match is not None:
            remaining = path[match.end():]
            groups = match.groupdict()
            result = {}
            for name, value in groups.items():
                try:
                    value = self._converters[name].to_python(value)
                except Http404:
                    return
                result[str(name)] = value
            if remaining:
                result['__remaining__'] = remaining
            return result
118750
function match(path) {

  if (!patterns) {
    patterns = fis.media().get('project.files', []);

    if (!Array.isArray(patterns)) {
      patterns = [patterns];
    }

    patterns = patterns.map(function(pattern) {
      var negate = false;

      if (pattern[0] === '!') {
        negate = true;
        pattern = pattern.substring(1);
      }

      pattern[0] === '/' && (pattern = pattern.substring(1));

      return {
        negate: negate,
        reg: _.glob(pattern)
      };
    });
  }

  path.indexOf(root) === 0 && (path = path.substring(root.length));

  var hitted = false;
  patterns.forEach(function(item) {
    if (hitted) {
      if (item.negate && item.reg.test(path)) {
        hitted = false;
      }
    } else {
      hitted = item.negate !== item.reg.test(path);
    }
  });

  return hitted;
}
333757
function isPathMatchSelector(path, selector){
  function isMatch(path, selector){
    path = typeof path == 'string' ? parseRole(path) : path || '';
    selector = typeof selector == 'string' ? parseRole(selector) : selector || '';

    return selector.role == path.role &&
           (selector.roleId == '*' || selector.roleId == path.roleId) &&
           selector.subrole == path.subrole;
  }

  var pathIndex = path.length;
  var selectorIndex = selector.length;

  if (!selectorIndex)
    return true;

  if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
    return false;

  while (pathIndex > 0 && selectorIndex > 0)
    if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
      selectorIndex++;

  return selectorIndex === 0;
}
5643
def items(self, path=None):
        
        items = list(self.iteritems())
        if path is not None:
            path += '$'
            regex = re.compile(path)
            items = [i for i in items if regex.match(i.path)]
        return items
746524
@SuppressWarnings("unchecked")
  private static Collection match(final OptionElement subroot,
                                  final String[] pathElements, int pos) {

    if (pos >= 0) {
      // Not at root.
      if (!pathElements[pos].equals(subroot.name)) {
        return null;
      }
    }

    if (subroot.isValue) {
      // pos must be last entry
      if ((pos + 1) != pathElements.length) {
        return null;
      }
      ArrayList res = new ArrayList();

      res.add(subroot.val);
      return res;
    }

    ArrayList res = new ArrayList();

    pos++;
    if (pos == pathElements.length) {
      /* return all the children of this level */

      for (OptionElement optel: subroot.getChildren()) {
        if (optel.isValue) {
          res.add(optel.val);
        }
      }

      return res;
    }

    for (OptionElement optel: subroot.getChildren()) {
      Collection subres = match(optel, pathElements, pos);
      if (subres != null) {
        res.addAll(subres);
      }
    }

    return res;
  }
97755
function (path) {
            // edge case
            if (!path) {
                return [];
            }

            // first letter will give the type
            var first = path.charAt(0), closing, part, next, nextParse;

            // case brackets
            if (first == "[") {
                closing = path.indexOf("]");
                if (closing != -1) {
                    part = path.substring(1, closing);
                    next = path.substring(closing + 1);
                    if (/^\d+$/.test(part)) {
                        nextParse = this._paramParse(next);
                        nextParse.unshift(parseInt(part, 10));
                        return nextParse;
                    } else {
                        // check that part is "something" or 'somethingelse'
                        var strMarker = part.charAt(0), utilString = ariaUtilsString;
                        if ((strMarker == "'" || strMarker == '"')
                                && utilString.indexOfNotEscaped(part, strMarker, 1) == part.length - 1) {
                            nextParse = this._paramParse(next);
                            nextParse.unshift(part.substring(1, part.length - 1).replace(new RegExp("\\\\" + strMarker, "gi"), strMarker));
                            return nextParse;
                        }
                    }
                }
            } else if (first == ".") {
                part = /^[_A-z\$]\w*/.exec(path.substring(1));
                if (part.length) {
                    part = part[0];
                    next = path.substring(part.length + 1);
                    nextParse = this._paramParse(next);
                    nextParse.unshift(part);
                    return nextParse;
                }
            }

            // nothing returned -> throws an exception
            throw {
                error : this.WRONG_PATH_SYNTAX,
                args : [path]
            };
        }
912346
function PathExpression(path) {
  const iterPattern = /^(.*)\[(\d+)]$/;
  const paths = path.split('.').reduce((prev, key) => {
    const matches = key.match(iterPattern);
    if (matches) {
      const [, rest, index] = matches;
      return [...prev, t.stringLiteral(rest), c.KEY_I(index)];
    }
    return [...prev, t.stringLiteral(key)];
  }, []);

  return paths;
}
104957
public static boolean matches(Pattern patternMatcher, Object... elements)
    {
        if (patternMatcher == null) {
            return true;
        }

        for (Object element : elements) {
            if (matches(patternMatcher, element)) {
                return true;
            }
        }

        return false;
    }
67618
public List getMatches(String path)
    {        
        Map.Entry entry;
        Object entries=null;

        if (path==null)
            return LazyList.getList(entries);
        
        int l=path.indexOf(';');
        if (l<0)
        {
            l=path.indexOf('?');
            if (l<0)
                l=path.length();
        }

        // try exact match
        entry=_exactMap.getEntry(path,0,l);
        if (entry!=null)
            entries=LazyList.add(entries,entry.getValue());
        
        // prefix search
        int i=l-1;
        while((i=path.lastIndexOf('/',i-1))>=0)
        {
            entry=_prefixMap.getEntry(path,0,i);
            if (entry!=null)
                entries=LazyList.add(entries,entry.getValue());
        }
        
        // Prefix Default
        if (_prefixDefault!=null)
            entries=LazyList.add(entries,_prefixDefault);
        
        // Extension search
        i=0;
        while ((i=path.indexOf('.',i+1))>0)
        {
            entry=_suffixMap.getEntry(path,i+1,l-i-1);
            if (entry!=null)
                entries=LazyList.add(entries,entry.getValue());
        }

        // Default
        if (_default!=null)
        {
            // Optimization for just the default
            if (entries==null)
                return _defaultSingletonList;
            
            entries=LazyList.add(entries,_default);
        }
        
        return LazyList.getList(entries);
    }
676012
static private boolean hasFileMatch(String path, List<String> patterns) {
        path = Util.normalizeDriveLetter(path);
        for (String p : patterns) {
            // Exact match
            if (p.equals(path)) {
                return true;
            }
            // Single dot the end matches this package and all its subpackages.
            if (p.startsWith("*")) {
                // Remove the wildcard
                String patsuffix = p.substring(1);
                // Does the path start with the pattern prefix?
                if (path.endsWith(patsuffix)) {
                    return true;
                }
            }
        }
        return false;
    }