A Python package that expands template strings with various placeholders including optional groups, alternatives, and character sets.
To install py_template_expander, use pip:
pip install py_template_expanderThe expand function takes a template string and yields all possible expanded strings.
Here's a simple example:
from py_template_expander import expand
template1 = "Hello (world|there)!"
print("Expanding: ", template1)
for expansion in expand(template1):
print(expansion)
# Expected output:
# Expanding: Hello (world|there)!
# Hello world!
# Hello there!
template2 = "The quick [abc] fox."
print("\nExpanding: ", template2)
for expansion in expand(template2):
print(expansion)
# Expected output:
# Expanding: The quick [abc] fox.
# The quick a fox.
# The quick b fox.
# The quick c fox.
template3 = "Optional: (item1|item2) and (optional|)"
print("\nExpanding: ", template3)
for expansion in expand(template3):
print(expansion)
# Expected output:
# Expanding: Optional: (item1|item2) and (optional|)
# Optional: item1 and optional
# Optional: item1 and
# Optional: item2 and optional
# Optional: item2 and
# Optional: and optional
# Optional: and- Optional Groups: Use
(pattern)for parts that may or may not appear. - Alternatives: Use
|within parentheses to specify choices, e.g.,(A|B). - Character Sets: Use
[abc]to match any single character within the brackets.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
py_template_expander is licensed under the MIT License.
Eugene Evstafev
- LinkedIn: eugene-evstafev-716669181
- Email: hi@eugene.plus