# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\]\sA\s+(.*)(microsoft|office|azure|o365|onenote|outlook|windowsupdate)(\(\d+\))(com|net|us)(\(\d+\))\s"
test_str = ("10/6/2023 6:19:18 AM 149C PACKET 0000023A2A31D8A0 UDP Rcv 10.106.92.80 e32e Q [0001 D NOERROR] A (6)mobile(4)pipe(4)aria(9)microsoft(3)com(0)\n"
"UDP question info at 0000023A2A31D8A0\n"
" Socket = 816\n"
" Remote addr 10.106.92.80, port 54599\n"
" Time Query=5683788, Queued=0, Expire=0\n"
" Buf length = 0x0fa0 (4000)\n"
" Msg length = 0x0030 (48)\n"
" Message:\n"
" XID 0xe32e\n"
" Flags 0x0100\n"
" QR 0 (QUESTION)\n"
" OPCODE 0 (QUERY)\n"
" AA 0\n"
" TC 0\n"
" RD 1\n"
" RA 0\n"
" Z 0\n"
" CD 0\n"
" AD 0\n"
" RCODE 0 (NOERROR)\n"
" QCOUNT 1\n"
" ACOUNT 0\n"
" NSCOUNT 0\n"
" ARCOUNT 0\n"
" QUESTION SECTION:\n"
" Offset = 0x000c, RR count = 0\n"
" QTYPE A (1)\n"
" QCLASS 1\n"
" ANSWER SECTION:\n"
" empty\n"
" AUTHORITY SECTION:\n"
" empty\n"
" ADDITIONAL SECTION:\n"
" empty")
matches = re.finditer(regex, test_str, re.MULTILINE)
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