I need help pulling out a repeated block of config from a FortiGate firewall config file. It contains various sections in the format below.
Each of the vdom config sections ('config vdom' section) end with 2 'end's - I need to pull these blocks out as a first step before the next steps.
#header info
config vdom
edit root
next
edit test
next
edit test2
next
end
config global
...
...
...
end
end
config vdom
edit root
config system
...
end
config ...
...
...
......
...
end
end
config vdom
edit test
config system
...
end
config ...
...
...
......
...
end
end
config vdom
edit test2
config system
...
end
config ...
...
...
...
end
end
I'm using regex101.com to build the regex to use in a python script. Here's where I got so far.
(config vdom\nedit.+\nconfig[\s\S\r]*)
- matches all text starting with the first vdom config, until the end of the file, includes the other vdom config too
(config vdom\nedit.+\nconfig[\s\S\r]*?)
- matches only the first 3 lines until the first 'config'
(config vdom\nedit.+\nconfig[\s\S\r]*?end\n)
- matches text until the first occurrence of 'end' - there are multiple 'end's throughout the config, but there are 2 of them at the end of each vdom config
(config vdom\nedit.+\nconfig[\s\S\r]*?end\nconfig)
- matches text until the first occurrence of 'config', but instead if I use 'end' like below to match two of them, it fails
(config vdom\nedit.+\nconfig[\s\S\r]*?end\nend\n\n)
- when trying to look for the occurrence of 2 ends followed by an empty line, it fails with 'catastrophic backtracking'
I don't know why it works when I use one end\n
after the *?
but fails as soon as I try adding the second one.
Any help will be greatly appreciated!