# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"DELETE.*?DELETE[^\n]*\n(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
test_str = ("192.168.10.20 - - [18/Jul/2017:08:41:37 +0000] \"DELETE /search/tag/list HTTP/1.0\" 200 5042 \"http://cooper.com/homepage/\" \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/5342 (KHTML, like Gecko) Chrome/14.0.870.0 Safari/5342\"\n"
"10.30.24.3 - - [18/Jul/2017:08:45:15 +0000] \"DELETE /search/tag/list HTTP/1.0\" 200 4939 \"http://www.cole-brown.net/category/main/list/privacy/\" \"Mozilla/5.0 (X11; Linux i686) AppleWebKit/5322 (KHTML, like Gecko) Chrome/14.0.843.0 Safari/5322\"\n"
"98.5.45.3 - - [18/Jul/2017:08:45:49 +0000] \"GET /apps/cart.jsp?appID=8471 HTTP/1.0\" 200 4958 \"http://knight-chase.com/post.jsp\" \"Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_3; rv:1.9.6.20) Gecko/2013-11-03 17:44:01 Firefox/3.8\"")
matches = re.finditer(regex, test_str, re.DOTALL)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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