Closed mattgmoser closed 5 years ago
@mattgmoser pattern_match
uses the re
regular expression module from the Python standard library, which doesn't appear to support branch reset groups.
If your real world use case is as simple as the example provided above, putting the OR logic within the same capture group may suffice:
>>> re.search("(doggies|Cisco Nexus Operating)", 'some text with doggies').group(1)
'doggies'
>>> re.search("(doggies|Cisco Nexus Operating)", 'Cisco Nexus Operating System').group(1)
'Cisco Nexus Operating'
Thank you @blandrew , I was wondering if that was the case. I've been able to find a successful work-around, I appreciate your looking into this.
Python re
doesn't support branch reset which command_parser uses.
3rd party PyPi regex module supports a branch reset feature.
Hence command_parser
is failing.
Please file a bug report if you face issue further. Thanks!
ISSUE TYPE
ANSIBLE VERSION
Network OS
SUMMARY
I am attempting to utilize network-engine's command_parser to extract key facts, such as network device version number, from the device.
Because different versions of NXOS and IOS seem to present the data in a slightly different way, I was hoping to use a regex branch reset group to apply 'OR' logic to match the different variants of how the data is displayed to the same regex group.
STEPS TO REPRODUCE
To reproduce, attempt to use a branch reset group under 'regex' within pattern_match.
EXPECTED RESULTS
The above should match either 'doggies' or 'Cisco Nexus Operating' to regex group 1. This works fine on online Regex editors, but throws an error when I try this through command_parser.
regex101.com: Link to expected result example
ACTUAL RESULTS