# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?:AzureFirewallNetworkRule|AzureFirewallApplicationRule).*?(?<=to\s)(?<dest>[^(?:\.\s)].*)"
test_str = ("{\"category\": \"AzureFirewallNetworkRule\", \"time\": \"2023-03-29T20:00:53.4378840Z\", \"resourceId\": \"/SUBSCRIPTIONS/CA41E67C-1C2F-47D5-9252-402EDF21E20F/RESOURCEGROUPS/RG-PROD-CONNECTIVITY-EUS2/PROVIDERS/MICROSOFT.NETWORK/AZUREFIREWALLS/AZFW-HUB-PROD-EUS2\", \"operationName\": \"AzureFirewallNetworkRuleLog\", \"properties\": {\"msg\": \"ICMP Type=8 request from 10.0.2.5 to 10.252.0.133. Action: Allow. Policy: afwp-hub-prod-eus2. Rule Collection Group: global. Rule Collection: Allowed-Network-Rules. Rule: QuadToAzurePing\"}}\n\n"
"{\"category\": \"AzureFirewallNetworkRule\", \"time\": \"2023-03-29T19:54:03.8947510Z\", \"resourceId\": \"/SUBSCRIPTIONS/CA41E67C-1C2F-47D5-9252-402EDF21E20F/RESOURCEGROUPS/RG-PROD-CONNECTIVITY-EUS2/PROVIDERS/MICROSOFT.NETWORK/AZUREFIREWALLS/AZFW-HUB-PROD-EUS2\", \"operationName\": \"AzureFirewallNetworkRuleLog\", \"properties\": {\"msg\": \"TCP request from 10.252.0.158:50458 to 161.49.232.168:10002. Action: Allow. Policy: afwp-hub-prod-eus2. Rule Collection Group: global. Rule Collection: Allowed-Network-Rules. Rule: AzureToQuadInternalF5\"}}\n\n"
"{\"category\": \"AzureFirewallApplicationRule\", \"time\": \"2023-03-29T14:46:55.5760760Z\", \"resourceId\": \"/SUBSCRIPTIONS/CA41E67C-1C2F-47D5-9252-402EDF21E20F/RESOURCEGROUPS/RG-PROD-CONNECTIVITY-EUS2/PROVIDERS/MICROSOFT.NETWORK/AZUREFIREWALLS/AZFW-HUB-PROD-EUS2\", \"operationName\": \"AzureFirewallApplicationRuleLog\", \"properties\": {\"msg\": \"HTTPS request from 10.252.0.158:50868 to login.microsoftonline.com:443. Action: Allow. Policy: afwp-hub-prod-eus2. Rule Collection Group: global. Rule Collection: Allowed-Application-Rules. Rule: AzureAD\"}}\n\n"
"{\"category\": \"AzureFirewallApplicationRule\", \"time\": \"2023-03-29T20:50:13.0977850Z\", \"resourceId\": \"/SUBSCRIPTIONS/CA41E67C-1C2F-47D5-9252-402EDF21E20F/RESOURCEGROUPS/RG-PROD-CONNECTIVITY-EUS2/PROVIDERS/MICROSOFT.NETWORK/AZUREFIREWALLS/AZFW-HUB-PROD-EUS2\", \"operationName\": \"AzureFirewallApplicationRuleLog\", \"properties\": {\"msg\": \"HTTP request from 10.252.0.158:50039 to google.com:80. Action: Deny. No rule matched. Proceeding with default action\"}}")
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