def expand_wildcards(wildcards, candidates, recursive=False):
  '''
  wildcards is a list of paths that includes wildcards, and candidates are paths that the wildcards match.
  Return a list of non-wildcard paths
  '''
  out = []
  match_char = '.' if recursive else '[^/]'
  for wildcard in wildcards:
    if '*' in wildcard or '?' in wildcard:
      pattern = r'^' + re.escape(wildcard).replace('\\*', match_char + '*').replace('\\?', match_char) + r'$'
      out.extend([candidate for candidate in candidates if re.search(pattern, candidate) is not None])
    else:
      out.append(wildcard)
  return out

# Color texts to display in Terminal
dataset/ETHPy150Open bloomreach/zinc/zinc.py/expand_wildcards/original