network-programmingpython-textfsm

match string from end on TextFSM


Would like match output from end of line to white space

netmgmt@CCC-CC-CCC-RE1> show lldp neighbors Local Interface Parent Interface Chassis Id Port info System Name xe-11/3/0 ae2 00:23:9c:d5:7f:c0 295 BAZ-CPR01-RE1
xe-10/3/0 ae2 00:23:9c:d5:7f:c0 306 BAZ-CPR01-RE1
xe-8/3/0 ae1 00:23:9c:dd:a7:c0 xe-10/3/0 UKW-CPR02-RE1
xe-9/3/0 ae1 00:23:9c:dd:a7:c0 xe-11/3/0 UKW-CPR02-RE1

I cant use left to string regex matching, cause i may see white spaces in port info tab, so i am trying to match from end.

I believe $ i use here for end, may be matching with ${variable} and causing problems.

I used regex101.com and able to match last word in lines using:((\S+\s+)$)

Value List local_interface (\S+)
Value ae_interface (\S+)
Value lldp_device ((\S+\s+)$)

Start
  ^Local.*Name -> LLDP

LLDP
  ^${local_interface}\s+${ae_interface}\s+${lldp_device} -> Record

Expected: BAZ-CPR01-RE1 BAZ-CPR01-RE1 UKW-CPR02-RE1 UKW-CPR02-RE1

Result : []


Solution

  • You will have to use $$ for this.

    To indicate the end of line (EOL) use a double dollar sign '$$', this will be substituted for a single dollar sign during Value substitution.

    https://github.com/google/textfsm/wiki/TextFSM