dotfiles/common/util.py
2024-08-08 12:28:10 +02:00

15 lines
392 B
Python

import re
def expand(pattern: str) -> list[str]:
match = re.search(r'\{([^{}]*)\}', pattern)
if not match:
return [pattern]
pre, post = pattern[:match.start()], pattern[match.end():]
options = match.group(1).split(',')
expanded_patterns = []
for option in options:
expanded_patterns.extend(expand(pre + option + post))
return expanded_patterns