I am trying to match a datatime inside square brackets and I thought prefixing "\" would be the way to encode square brackets but somehow it didn't work. Here is my code:
import re
line_nginx = re.compile(r"""\[(?P<time_local>\S+) -700\]""", re.IGNORECASE)
match = line_nginx.match("[07/Oct/2014:19:43:08 -0700]")
if match:
print("matched")
else:
print("no match")
I got "no match". Any idea what went wrong?