An example of a configuration section with no "obvious" boundaries can be seen in Nortel VLAN or Cisco CatOS access list configurations. There are no decisive or obvious boundaries to build your begin-with and end-with patterns against to properly split the groupings. For example, Nortel VLAN configurations will begin after a comment line, will have groupings of one or more lines prefixed with the same VLAN number, will only roll the VLAN number between groupings, and then end with another comment line:
#
vlan 1 option one
vlan 10 option one
vlan 10 option two
vlan 10 option three
vlan 20 option one
vlan 20 option two
#
In comparison, Cisco IOS interfaces are simple to split because they always start and end with "interface" and "!" respectively. These boundaries are obvious:
!
interface ethernet 1/10
desc my interface
!
interface ethernet 2/10
desc my interface
!
In order to separate and process each vlan grouping from the vlan example, you can use the following syntax in your precondition:
This makes use of a capture group, a negative lookahead and a back reference . The VLAN number is captured in the begin-with precondition via "(\d+)". The end-with precondition uses a negative lookahead "(?!)" to match anything that is not "vlan \1". The back reference "\1" recalls the characters matched by the first capture group. By using the back reference inside the negative lookahead, the end-with pattern will only stop grouping at a VLAN line that is not the same VLAN number matched from the begin-with pattern, or a trailing comment line. It has the affect of splitting the example configuration into three pieces:
vlan 1 option one
vlan 10 option one
vlan 10 option two
vlan 10 option threevlan 20 option one
vlan 20 option two
From here you can begin crafting check patterns and remedies to process against the VLAN groupings, but there are a few other things that allow this to work that should be pointed out: