If the pattern is not null, it will attempt to match against the supplied name to pull out the source.
559122
public static SourceInformation from(Pattern sourceRegex, String name) {
        if (sourceRegex == null) {
            return new SourceInformation(null, name);
        }
        Matcher matcher = sourceRegex.matcher(name);
        if (matcher.groupCount() != 1) {
            log.error("Source regex matcher must define a group");
            return new SourceInformation(null, name);
        }
        if (!matcher.find()) {
            return new SourceInformation(null, name);
        }
        String source = matcher.group(1);
        int endPos = matcher.toMatchResult().end();
        if (endPos >= name.length()) {
            // the source matched the whole metric name, probably in error.
            log.error("Source '{}' matched the whole metric name. Metric name cannot be empty");
            return new SourceInformation(null, name);
        }
        String newName = name.substring(endPos);
        return new SourceInformation(source, newName);
    }
718498
def imatch(pattern, name):
    # type: (Text, Text) -> bool
    
    try:
        re_pat = _PATTERN_CACHE[(pattern, False)]
    except KeyError:
        res = "(?ms)" + _translate(pattern, case_sensitive=False) + r'\Z'
        _PATTERN_CACHE[(pattern, False)] = re_pat = re.compile(res, re.IGNORECASE)
    return re_pat.match(name) is not None
856631
function replaceFilenameTokens(pattern, next) {
        if (pattern.match(/%[bf]/)) {
          if (typeof source !== 'string') {
            return next(new Error('Cannot replace %f or %b when using an input stream'));
          }

          pattern = pattern
            .replace(/%f/g, path.basename(source))
            .replace(/%b/g, path.basename(source, path.extname(source)));
        }

        next(null, pattern);
      }
231074
private MatchManyWrapper findMatchManyWrapper(PatternWrapper pattern)
  {
    MatchManyWrapper wrapper = null;
    if (matchManyChildren != null)
    {
      // Iterate over the matchManyChildren
      Iterator iter = matchManyChildren.iterator();

      while(iter.hasNext())
      {
        MatchManyWrapper nextElement = (MatchManyWrapper) iter.next();
        PatternWrapper nextPattern = nextElement.pattern;
        if(nextPattern.equals(pattern))
        {
          // We're done, we've found the matching pattern
          wrapper = nextElement;
          break;
        }
      } // eof while more children in the list
    }
    return wrapper;
  }
834029
private boolean isDeeper(String pattern, String name) {
        Vector p = SelectorUtils.tokenizePath(pattern);
        Vector n = SelectorUtils.tokenizePath(name);
        return p.contains("**") || p.size() > n.size();
    }
478166
def compare(self, origin, pattern):
        

        if origin is None or pattern is None:
            return False
        return re.match(pattern, origin) is not None
936849
def match(self, selector, index):
        """"""

        pseudo = None
        m = self.re_pseudo_name.match(selector, index)
        if m:
            name = util.lower(css_unescape(m.group('name')))
            pattern = self.patterns.get(name)
            if pattern:
                pseudo = pattern.match(selector, index)
                if pseudo:
                    self.matched_name = pattern

        return pseudo
1051153
public static boolean endsWithIgnoreCase(String name, Iterable<String> patterns) {
        String nameUpper = name.toUpperCase();
        for (String pattern : patterns) {
            String patternUpper = pattern.toUpperCase();
            if (nameUpper.equals(patternUpper) || nameUpper.endsWith(patternUpper)) {
                return true;
            }
        }

        return false;
    }
138335
function maybe_name() {
  skip_horiz_white();
  if (look(ident_pattern_with_dot)) {
    current_tag["name"] = match(ident_pattern_with_dot);
  }
  else if (look(ident_pattern)) {
    current_tag["name"] = match(ident_pattern);
  }
}
1229864
public static boolean safeRegexMatch(String pattern, String value) {
        if (StringUtils.isNotBlank(pattern)) {
            if (value == null) {
                return false;
            } else {
                try {
                    return Pattern.matches(pattern, value);
                } catch (PatternSyntaxException ex) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
267824
public boolean sourceExists(String name) {

        if (name != null && name.equals(getTemplateName())) {
            return true;
        }

        // Look for a .tea file
        return super.sourceExists(name);
    }
480018
private static boolean matchWildCards(String name, String template) {
        int wildcardIndex = template.indexOf("*");
        if (wildcardIndex == -1) {
            return name.equals(template);
        }

        boolean isBeginning = true;
        String beforeWildcard;
        String afterWildcard = template;
        while (wildcardIndex != -1) {
            beforeWildcard = afterWildcard.substring(0, wildcardIndex);
            afterWildcard = afterWildcard.substring(wildcardIndex + 1);

            int beforeStartIndex = name.indexOf(beforeWildcard);
            if ((beforeStartIndex == -1) || (isBeginning && beforeStartIndex != 0)) {
                return false;
            }
            isBeginning = false;

            name = name.substring(beforeStartIndex + beforeWildcard.length());
            wildcardIndex = afterWildcard.indexOf("*");
        }

        return name.endsWith(afterWildcard);
    }
815085
public static @Nonnull Predicate nameContains(final @Nonnull Pattern pattern) {
        return new Predicate() {
            @Override
            public boolean isValid(@Nonnull ProcessThread<?, ?, ?> thread) {
                return pattern.matcher(thread.getName()).find();
            }
        };
    }
1153360
def match(self, name):
		''''''
		if (self.ns + self.name).startswith(name):
			return True

		for alias in self.aliases:
			if (self.ns + alias).startswith(name):
				return True
1316751
private String matchPatternInBuffer(Pattern pattern) {
        matchValid = false;
        matcher.usePattern(pattern);
        matcher.region(position, buf.limit());
        if (matcher.lookingAt()) {
            if (matcher.hitEnd() && (!sourceClosed)) {
                // Get more input and try again
                needInput = true;
                return null;
            }
            position = matcher.end();
            return matcher.group();
        }

        if (sourceClosed)
            return null;

        // Read more to find pattern
        needInput = true;
        return null;
    }
878166
private static boolean check(String data, Pattern pattern) {
        if (StringUtils.isEmpty(data)) {
            return false;
        }
        Matcher matcher = pattern.matcher(data);
        return matcher.matches();
    }
529455
private static function isFileNamePatternMatch($name, $pattern, $options) {
    if (in_array($name, static::$excluded_file_names)) {
      return false;
    }

    $fnmatch_flags = 0;
    if ($options & GLOB_NOESCAPE) {
      $fnmatch_flags |= FNM_NOESCAPE;
    }

    return fnmatch($pattern, $name, $fnmatch_flags);
  }