# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^(?P<alb_type>(https?|h2|wss?))\s*(?P<alb_timestamp>[^\s]+)\s*(?P<alb_elb>[^\s]+)\s*(?P<alb_client_addr>[^:]+):\s*(?P<alb_client_port>[^\s]+)\s*(?P<alb_target_addr>[^:]+):\s*(?P<alb_target_port>[^\s]+)\s*\s*(?P<alb_request_processing_time>[^\s]+)\s*(?P<alb_target_processing_time>[^\s]+)\s*(?P<alb_response_processing_time>[^\s]+)\s*(?P<alb_elb_status_code>[^\s]+)\s*(?P<alb_target_status_code>[^\s]+)\s*(?P<alb_received_bytes>[^\s]+)\s*(?P<alb_sent_bytes>[^\s]+)\s*\"(?P<alb_request>.*?)\"\s+\"(?P<alb_user_agent>[^\"]+)\"\s*(?P<alb_ssl_cipher>[^\s]+)\s*(?P<alb_ssl_protocol>[^\s]+)\s*(?P<alb_target_group_arn>[^\s]+)\s*\"(?P<alb_trace_id>[^\"]+)\"\s*\"(?P<alb_domain_name>[a-zA-Z0-9\.\-:]+)\"\s*\"(?P<alb_chosen_cert_arn>[^\"]+)\"\s*(?P<alb_matched_rule_priority>[^\s]+)\s*(?P<alb_request_creation_time>[^\s]+)\s*\s*\"(?P<alb_actions_executed>[^\s]+)\"\s*\"(?P<alb_redirect_url>[^\s]+)\"\s*\"(?P<alb_error_reason>[^\"]+)\"\s*\"?(?P<alb_target_port_list>[0-9 :\.-]+)\"?\s*\"?(?P<alb_target_status_code_list>[0-9 -]+)\"?"
test_str = ("https 2021-12-28T08:45:46.363601Z app/k8s-internaltelioalb-0189d12367/7b3deb885c66a05c 10.50.8.89:59718 10.50.16.243:3000 0.000 0.702 -1 502 - 492 272 \"POST https://api-internal.prd.telio.me:443/internal/oms/graphql HTTP/1.1\" \"axios/0.21.1\" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:ap-southeast-1:305671018540:targetgroup/k8s-telio-omsservi-0d37efa96a/62501827cfb001cc \"Root=1-61caceb9-7c362e4c422488481a886f20\" \"api-internal.prd.telio.me\" \"arn:aws:acm:ap-southeast-1:305671018540:certificate/1389500b-1e0f-4bb9-bfee-2356cf20f40d\" 3 2021-12-28T08:45:45.658000Z \"forward\" \"-\" \"-\" \"10.50.16.243:3000\" \"-\" \"-\" \"-\"\n"
"https 2021-12-28T08:46:08.788818Z app/k8s-internaltelioalb-0189d12367/7b3deb885c66a05c 10.50.8.77:46086 10.50.16.243:3000 0.000 3.849 -1 502 - 492 272 \"GET https://api-internal.prd.telio.me:443/internal/oms/graphql?query=query%7B%0A++++++++++warehouseByCustomer(%0A++++++++++++verticalId:+%22null%22,%0A++++++++++++customerId:+%2238311%22,%0A++++++++++++addressId:+109138,%0A++++++++++++warId:+119101103,%0A++++++++++)%7B%0A++++++++++++id,%0A++++++++++++storeId,%0A++++++++++++name%0A++++++++%7D%7D HTTP/1.1\" \"axios/0.19.2\" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:ap-southeast-1:305671018540:targetgroup/k8s-telio-omsservi-0d37efa96a/62501827cfb001cc \"Root=1-61cacecc-1a87e41c30f7191a28b89096\" \"api-internal.prd.telio.me\" \"session-reused\" 3 2021-12-28T08:46:04.939000Z \"forward\" \"-\" \"-\" \"10.50.16.243:3000\" \"-\" \"-\" \"-\"")
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