Yes, I didn't try to post a rigid grammar since I assumed the expression was simple and self-explanatory. But there is no substitute for unambiguous representation. I came to know about BNF for the first time through your post, thanks a lot!
Here is my attempt to describe Cisco's ACL grammar using BNF. Hope my grammar is right!
<acl> ::= "access-list" <interface-name> <action> <protocol> <sou +rce> <destination> <port> <action> ::= "permit" | "deny" <protocol> ::= "tcp" | "udp" | "ip" | "object-group" <object-group- +name> <source> ::= "object-group" <object-group-name> | "host" <host-ad +dress> | <network-address> <net-mask> <destination> ::= "object-group" <object-group-name> | "host" <host-ad +dress> | <network-address> <net-mask> <port> ::= "eq" <port-number> | "range" <low-port> <high-port> +| ""
The strings that I want to capture in my code are <action>, <protocol>, <source>, <destination>, <port>. Sorry for my previous ambiguous post.
If regexes are not the best way to decode this, how else can I do? I basically want to learn a solid way to deal with the config files, instead of using nested if's or tracking using a dodgy index variable.
In reply to Re^2: Regex to match a Cisco ACL
by Anonymous Monk
in thread Regex to match a Cisco ACL
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |