Suppose I have two strings, a template and target string.
Template string: "param1~{wildcard1}/param2~{wildcard2}_param3~{wildcard3}"
Target string: "param1~1.1/param2~a_b_c_param3~345"
I would like to create a function that takes in a template string and target string as arguments. The function returns a wildcard object (or dictionary, or some data structure that can hold key-value pairs) where the key is the wildcard name (i.e wildcard1) and the value is the value of the wildcard in the target string (i.e 1.1)
Here's a little example:
def extract_wildcards(template, target):
... (implementation) ...
return wildcards
Usage:
wildcards = extract_wildcards("param1~{wildcard1}/param2~{wildcard2}_param3~{wildcard3}",
"param1~1.1/param2~a_b_c_param3~345")
print(wildcards.wildcard1)
>"1.1"
print(wildcards.wildcard2)
>"a_b_c"
print(wildcards.wildcard3)
>"345"
Note that type casting is not necessary! All the values should strings. Wildcard names in the template will always be surrounded by {}. For the target string, you can assume that there is always only 1 way to extract wildcard values (no ambiguity in terms of what the each wildcard can be)