I tried this code but it doesn't work; I cannot catch anything. I need to get a multiline match and have been working 3 days on it now. Thanks for your help!!
My regex:
print(re.findall(r'^ltm\s+pool\s+/Common/[0-9-A-Z_.-]+\s+\{([\s\S]*?)^\}',file.read(), re.MULTILINE))
print(re.findall(r'^ltm\s+pool\s+/Common/[0-9-A-Z_.-]+\s+\{(.*?)^\}',file.read(), re.DOTALL))
My code:
#!/usr/bin/env python3
import re, os, sys
### We create a new file
f = open("bigip.txt", "w")
### Default stdout value copied to a variable
orig_stdout = sys.stdout
### Stdout transfered to a file in write mode
sys.stdout = open("bigip.txt", "w")
file = open("bigiptemp", "r")
#for line in file:
#if re.findall(r'^ltm\spool\s\/Common\/([A-Z-a-z]+)', line):
#print(line)
print(re.findall(r'^ltm\s+pool\s+/Common/[0-9-A-Z_.-]+\s+\{([\s\S]*?)^\}',file.read(), re.MULTILINE))
### Default stdout reset
sys.stdout = orig_stdout
The file below is an extract:
ltm pool /Common/GEOG.GD {
members {
/Common/
address
}
/Common/
address
}
monitor
}
ltm pool /Common/HAP_NAODE_DEV {
members {
/Common
address
}
/Common
address
}
}
monitor
}
The expected behavior is the following but I cannot share the content of bigiptemp ... But my previous answer was tagged as duplicate ... Regular expression works on regex101.com, but not on prod