Closed matrix273 closed 1 year ago
Hello, resuball
iterates over all patterns and performs replacement for each of them, it would not work well for this case, probably easier to use macro function e.g.:
<macro>
def add_capab(match):
res = []
items = match.split(" ")
for item in items:
if item == "T":
res.append("Trans Bridge")
elif item == "S":
res.append("Switch")
elif item == "r":
res.append("Repeater")
elif item == "R":
res.append("Router")
else:
res.append(item)
return " ".join(res)
</macro>
<group name="results*">
{{device}} {{ interface |ORPHRASE }} {{holdtime|DIGIT}} {{capability|ORPHRASE|macro("add_capab")}} {{platform}} {{port_id|ORPHRASE}}
</group>
Thanks for you reply,
dmulyalin @.***> 于2023年4月30日周日 07:33写道:
Hello, resuball iterates over all patterns and performs replacement for each of them, it would not work well for this case, probably easier to use macro function e.g.:
def add_capab(match): res = [] items = match.split(" ") for item in items: if item == "T": res.append("Trans Bridge") elif item == "S": res.append("Switch") elif item == "r": res.append("Repeater") elif item == "R": res.append("Router") else: res.append(item) return " ".join(res) {{device}} {{ interface |ORPHRASE }} {{holdtime|DIGIT}} {{capability|ORPHRASE|macro("add_capab")}} {{platform}} {{port_id|ORPHRASE}} — Reply to this email directly, view it on GitHub https://github.com/dmulyalin/ttp/issues/105#issuecomment-1528896157, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF5IDZCYRCBY4EBBKEVXIXLXDWQMHANCNFSM6AAAAAAXK3I5HE . You are receiving this because you authored the thread.Message ID: @.***>
I will use macro to replace it.
I want use "resuball" functions to replace "R" to "Router","r" to "Repeater" ,but the result does't match I wanted.
Data
Template
Result
As you see,the resuball functions execution many times on "capability". does't match I wanted.
How do I get the result below