Aug-22-2023, 11:50 PM
(This post was last modified: Aug-22-2023, 11:50 PM by deanhystad.)
I figured out what it was doing right away, but it took a while to find in the documentation. Unless told otherwise, ttd replace digits with \d, so 'IPV4 configuration' and 'IPv6 configuration' make identical patterns. I finally found it under Indicators.
https://ttp.readthedocs.io/en/latest/Mat...ght=digits
_exact_
{{ name | _exact_ }}
By default, the parser will replace all digits in a template with the ‘d+’ pattern. However, if _exact_ is present in any match variable within a line, digits will remain unchanged and parsed as is.
This is an important consideration for when a pattern contains numbers.
Your pattern should be:
https://ttp.readthedocs.io/en/latest/Mat...ght=digits
_exact_
{{ name | _exact_ }}
By default, the parser will replace all digits in a template with the ‘d+’ pattern. However, if _exact_ is present in any match variable within a line, digits will remain unchanged and parsed as is.
This is an important consideration for when a pattern contains numbers.
Your pattern should be:
import json from ttp import ttp temp = """ System Info IPv4 configuration : {{ ipv4_configuration | _exact_ }} IPv6 configuration : {{ ipv6_configuration | _exact_ }} """ data_to_parse = """ System Info IPv4 configuration : Disabled IPv6 configuration : Enabled """ parser = ttp(data=data_to_parse, template=temp) parser.parse() result = json.loads(parser.result(format="json")[0])[0] print(result)