make str pattern to regexp http://en.wikipedia.org/wiki/Glob_(programming)
184164
function (str) {
    if (caches[str]) {
      return caches[str];
    }
    
    // special regexp chars (., +, etc.)
    reg = str.replace(/[.+^$()|{}]/g, function (match, offset, s) {
      return s[offset - 1] === '\\' ? match : '\\' + match;
    });
    // ? and *
    reg = reg.replace(/[?*]/g, function (match, offset, s) {
      if (s[offset - 1] === '\\') {
        return match;
      }
      return match === '?' ? '.' : '.*';
    });
    // special regexp escapings (\d, \S, etc.)
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
    reg = reg.replace(/\\([dDsSwWtrnvfbB0cxu])/g, '$1');
    return caches[str] = new RegExp('^' + reg + '$');
  }
640363
def match_string(pattern, search_string):
    '''
    
    '''

    rexobj = REX(pattern, None)

    rexpatstr = reformat_pattern(pattern)
    #print "rexpatstr: ", rexpatstr

    rexpat = re.compile(rexpatstr)
    rexobj.rex_patternstr = rexpatstr
    rexobj.rex_pattern = rexpat

    line_count = 1
    for line in search_string.splitlines():
        line = line.strip()
        mobj = rexpat.match(line)
        if mobj:
            populate_resobj(rexobj, mobj, line_count)
        line_count += 1

    return rexobj
47018
def super_glob(pattern):
    ''
    pieces = pattern.split('/')
    if '**' in pieces:
        prefix = '/'.join(pieces[:pieces.index('**')])
        postfix = '/'.join(pieces[pieces.index('**') + 1:])
        roots = [dirname
                 for dirname, dirnames, filenames in os.walk(prefix)]
        patterns = [root + '/' + postfix for root in roots]
    else:
        patterns = ['/'.join(pieces)]
    return chain.from_iterable(glob(pattern) for pattern in patterns)
8854
function makeFilenameRegex(name) {
  if (!_.isString(name)) {
    throw new TypeError('name parameter must be of type "String"');
  }

  const regexString = `^${name}(?:[.](.+))?.(${fileExtensions.join('|')})$`;
  return new RegExp(regexString);
}
180565
function rtrim(str, targetStr) {
    var retStr = "";
    var regStr;

    if (typeof str != "string") {
        return retStr;
    }

    if (typeof targetStr != "string" || !targetStr) {
        targetStr = "\\s";
    }

    regStr = "(.*?)" + targetStr + "*$";
    regStr = new RegExp(regStr);

    str = str.replace(regStr, "$1");
    return str;
}
876790
function match(input, patterns = []){
	if(!patterns || 0 === patterns.length)
		return false;
	
	input    = String(input);
	patterns = arrayify(patterns).filter(Boolean);
	for(const pattern of patterns)
		if((pattern === input && "string" === typeof pattern)
		|| (pattern instanceof RegExp) && pattern.test(input))
			return true;
	return false;
}
1100469
def _short_ts_regexp():
	''''''
	ts_re = ['^']
	for k in it.chain(_short_ts_days, _short_ts_s):
		ts_re.append(r'(?P<{0}>\d+{0}\s*)?'.format(k))
	return re.compile(''.join(ts_re), re.I | re.U)
1163883
def extend_regex(regexpr):
    
    """
    regex_map = {
        #r'\<': r'\b(?=\w)',
        #r'\>': r'\b(?!\w)',
        r'\<': r'\b' + positive_lookahead(r'\w'),
        r'\>': r'\b' + negative_lookahead(r'\w'),
        ('UNSAFE', r'\x08'): r'\b',
    }
    for key, repl in six.iteritems(regex_map):
        if isinstance(key, tuple):
            search = key[1]
        else:
            search = key
        if regexpr.find(search) != -1:
            if isinstance(key, tuple):
                print('WARNING! Unsafe regex with: %r' % (key,))
            regexpr = regexpr.replace(search, repl)
    return regexpr
1208202
function parsePattern(pattern) {
	var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
	// Treat consecutive wildcards as one (#12)
	var wildCardPattern = /\*+/g;
	var endOfLinePattern = /\\\$$/;

	pattern = normaliseEncoding(pattern)

	if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
		return pattern;
	}

	pattern = pattern
		.replace(regexSpecialChars, '\\$&')
		.replace(wildCardPattern, '(?:.*)')
		.replace(endOfLinePattern, '$');

	return new RegExp(pattern);
}
54017
function (template) {
    var pattern = _.template(template)(fileReplace);
    pattern = pattern.replace(/\//g, '\\/');
    pattern = pattern.replace(/\s+/g, '\\s*');
    pattern = '\\s*' + pattern + '\\s*';
    return new RegExp(pattern);
}
1152089
def regexp_filter(self_or_cls, pattern):
        
        def inner_filter(name, p):
            name_match = re.search(pattern,name)
            if name_match is not None:
                return True
            doc_match = re.search(pattern,p.doc)
            if doc_match is not None:
                return True
            return False
        return inner_filter
1101602
def translate_pattern(glob):
    
    pat = ''

    # This will split on '/' within [character classes]. This is deliberate.
    chunks = glob.split(os.path.sep)

    sep = re.escape(os.sep)
    valid_char = '[^%s]' % (sep,)

    for c, chunk in enumerate(chunks):
        last_chunk = c == len(chunks) - 1

        # Chunks that are a literal ** are globstars. They match anything.
        if chunk == '**':
            if last_chunk:
                # Match anything if this is the last component
                pat += '.*'
            else:
                # Match '(name/)*'
                pat += '(?:%s+%s)*' % (valid_char, sep)
            continue  # Break here as the whole path component has been handled

        # Find any special characters in the remainder
        i = 0
        chunk_len = len(chunk)
        while i < chunk_len:
            char = chunk[i]
            if char == '*':
                # Match any number of name characters
                pat += valid_char + '*'
            elif char == '?':
                # Match a name character
                pat += valid_char
            elif char == '[':
                # Character class
                inner_i = i + 1
                # Skip initial !/] chars
                if inner_i < chunk_len and chunk[inner_i] == '!':
                    inner_i = inner_i + 1
                if inner_i < chunk_len and chunk[inner_i] == ']':
                    inner_i = inner_i + 1

                # Loop till the closing ] is found
                while inner_i < chunk_len and chunk[inner_i] != ']':
                    inner_i = inner_i + 1

                if inner_i >= chunk_len:
                    # Got to the end of the string without finding a closing ]
                    # Do not treat this as a matching group, but as a literal [
                    pat += re.escape(char)
                else:
                    # Grab the insides of the [brackets]
                    inner = chunk[i + 1:inner_i]
                    char_class = ''

                    # Class negation
                    if inner[0] == '!':
                        char_class = '^'
                        inner = inner[1:]

                    char_class += re.escape(inner)
                    pat += '[%s]' % (char_class,)

                    # Skip to the end ]
                    i = inner_i
            else:
                pat += re.escape(char)
            i += 1

        # Join each chunk with the dir separator
        if not last_chunk:
            pat += sep

    pat += r'\Z'
    return re.compile(pat, flags=re.MULTILINE|re.DOTALL)
1171322
function regEscape(str) {
  // essentially stolen from https://github.com/component/escape-regexp with a modified replacer
  return String(str).replace(/([.*+?=^!:${}()|[\]\/\\])/g, function (match, paren, index, orig) {
    if (match === ':' && orig[index + 1] !== '/')
      return match;
    
    // if star, it's a wildcard if only enclosed by forward slashes (or at start or end of string)
    if (match === '*' && (index === 0 || orig[index - 1] === '/') && (index + 1 === orig.length || orig[index + 1] === '/'))
      return '.*';
    
    return '\\' + match;
  });
}
6093
function normalize(pattern) {
        var type = toString.call(pattern);
        switch (type) {
            case '[object String]':
                return _.glob(pattern);
            case '[object RegExp]':
                return pattern;
            default:
                xgulp.log.error('invalid regexp [%s].', pattern);
        }
    }
773772
function makeGlobal(pattern) {
  var flags = 'g';

  if (pattern.multiline) flags += 'm';
  if (pattern.ignoreCase) flags += 'i';
  if (pattern.sticky) flags += 'y';
  if (pattern.unicode) flags += 'u';

  return new RegExp(pattern.source, flags);
}
872920
function rgx(regexp) {
        return new Pattern(regexp + '', function (str, pos) {
            var m = regexp.exec(str.slice(pos));
            if (m && m.index === 0) // regex must match at the beginning, so index must be 0
                return { res: m[0], end: pos + m[0].length };
        });
    }
748438
def file_matches_regexps(filename, patterns):
    """"""
    return any(re.match(pat, filename) for pat in patterns)