Regex replacement method that will sub paths when needed
177776
def _maybe_replace_path(self, match):
        
        path = match.group(0)
        if self._should_replace(path):
            return self._replace_path(path)
        else:
            return path
135657
def _extract_path_parameters_from_paths(paths):
    
    params = set()
    for path in paths:
        parts = PART_REGEX.split(path)
        for p in parts:
            match = PARAM_REGEX.match(p)
            if match:
                params.add(match.group("name"))
    return params
465298
def strip_trailing_slashes(self, path):
        """"""
        m = re.match(r"(.*)/+$", path)
        if (m is None):
            return(path)
        return(m.group(1))
982144
function(subPath, tokenMap, ignoreRegex) {
                if (typeof subPath !== 'string' || subPath.length === 0) {
                    return _folderPath;
                }
                tokenMap = tokenMap || {};
                ignoreRegex = !! ignoreRegex;

                var transform = _utils.getTransformer(tokenMap, ignoreRegex);
                subPath = transform(subPath);
                return _path.join(_folderPath, subPath);
            }
945209
def normalize_path(path)
    normalized_path = path.dup
    begin
      mod = nil
      mod ||= normalized_path.gsub!(RULE_2A, '/')

      pair = normalized_path.match(RULE_2B_2C)
      parent, current = pair[1], pair[2] if pair
      if pair && ((parent != '.' && parent != '..') ||
          (current != '.' && current != '..'))
        mod ||= normalized_path.gsub!(
          Regexp.new(
            "/#{Regexp.escape(parent.to_s)}/\\.\\./|" +
            "(/#{Regexp.escape(current.to_s)}/\\.\\.$)"
          ), '/'
        )
      end

      mod ||= normalized_path.gsub!(RULE_2D, '')
      # Non-standard, removes prefixed dotted segments from path.
      mod ||= normalized_path.gsub!(RULE_PREFIXED_PARENT, '/')
    end until mod.nil?

    return normalized_path
  end
219150
def parse_pattern(s):
    """"""
    if '{' in s:
        return None, None  # Unsupported by fnmatch
    if s and s[0] == '~':
        s = os.path.expanduser(s)
    parts = s.split('/')
    absolute = len(parts) > 1 and not parts[0]
    if parts[-1] == '':  # # Outcome of trailing /
        parts = parts[:-1]  # discard
    if len(parts) == 0:
        directory = ''
        pattern = ''
    else:
        directory = '/'.join(parts[:-1])
        pattern = parts[-1]
    if not is_pattern(directory): # Check for e.g. /abc/*/def
        if is_pattern(pattern):
            if not directory:
                directory = '/' if absolute else '.'
            return directory, pattern
    return None, None
412982
def make_pathable_string(s,replacewith='_'):
    
    import re
    return re.sub(r'[^\w+/.]',replacewith, s.lower())
1251111
def replace_path(path, name=nil)
      name ||= File.basename path
      self.replace_pattern path, name
    end
165079
function convertPathMatcher (cfg) {
				var pathMap = cfg.pathMap;
				cfg.pathRx = new RegExp('^(' +
					cfg.pathList.sort(function (a, b) { return pathMap[b].specificity - pathMap[a].specificity; } )
						.join('|')
						.replace(/\/|\./g, '\\$&') +
					')(?=\\/|$)'
				);
				delete cfg.pathList;
			}
199863
def fmt_subst(regex, subst):
    """"""
    return lambda text: re.sub(regex, subst, text) if text else text
283859
function filterPaths(paths, allowed) {
  if (!allowed) { return []; }
  if (!allowed.only.length) { return paths; }

  return paths.filter(
    path => {
      let match = false;

      for (const filter of allowed.only) {
        try {
          switch (typeof filter) {
            case 'function':
              match = filter(path.path);
              break;
            case 'string':
              match = path.path === filter;
              break;
            default:
              match = filter.test(path.path);
         }
        } catch (e) {
          throw new Error(`${ typeof filter } is not an allowed filter type. Must be String, RegExp or Function`);
        }
        if (match) { return match; }
      }
      return match;
    }
  );
}
748463
function(fsPath, strict) {
		if (!_.isString(fsPath)) {
			throw new TypeError('path must be of type string');
		}
		var segments = _.filter(fsPath.substring(fsPath.indexOf(path.sep) + 1).split(path.sep), function(segment) {
			return segment !== '';
		});
		for (var i = 0; i < segments.length; i++) {
			var replaceWith = module.exports.reformatSegment(segments[i], strict);
			var find = util.format('%s%s', replaceWith === '' ? path.sep : '', segments[i]);
			fsPath = fsPath.replace(find, replaceWith);
		}
		return fsPath;
	}
339640
function formatSubPath (path) {
  const trimmed = path.trim();
  // invalid leading 0
  if (path.charAt(0) === '0' && isNaN(path)) { return false }

  return isLiteral(trimmed) ? stripQuotes(trimmed) : '*' + trimmed
}
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);
      }
831862
def match_replace_regex(regex, src_namespace, dest_namespace):
    """"""
    match = regex.match(src_namespace)
    if match:
        return dest_namespace.replace("*", match.group(1))
    return None
1275671
function extractPathParams(pattern, path) {
    const regex = new RegExp(pattern);
    const matches = regex.exec(path);
    if (!matches) {
        return [];
    }
    else {
        const groups = [...matches];
        // remove first result since its not a capture group
        groups.shift();
        return groups;
    }
}
350479
def get_path_regex(self, path):
        
        for regex, func in self._regex_map:
            match = re.match(regex, path)
            if match:
                return func(match)

        return None, None