import re
regex = re.compile(r"[\r\n](# DO NOT TOUCH BEGIN[\n\r])?auto[ \t]+vmbr10[ \t]*[\n\r](?:[ \t]*.*[\n\r])*?[ \t]*bridge_maxwait[ \t]+0[ \t]*([\n\r]# DO NOT TOUCH END[\n\r])?")
test_str = ("auto vmbr9\n"
"iface vmbr9 inet static\n"
" address 10.109.0.2\n"
" netmask 255.255.0.0\n"
" bridge_ports none\n"
" bridge_stp off\n"
" bridge_fd 0\n"
" bridge_maxwait 0\n\n"
"auto vmbr10\n"
"iface vmbr10 inet static\n"
" up echo 1 > /sys/devices/virtual/net/vmbr10/bridge/multicast_snooping\n"
" up echo 0 > /sys/class/net/vmbr10/bridge/multicast_querier\n"
" address 10.111.0.2\n"
" netmask 255.255.0.0\n"
" bridge_ports none\n"
" bridge_stp off\n"
" bridge_fd 0\n"
" bridge_maxwait 0\n"
" post-up ip addr add 10.111.0.254/16 dev vmbr10")
match = regex.search(test_str)
if match:
print(f"Match was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html