dotfiles/common/util.py

16 lines
392 B
Python
Raw Normal View History

2024-08-08 12:28:10 +02:00
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