I am trying to extract data from a log into a dictionary. This is what the first line looks like:
146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622
I've managed to extract the IP into a dictionary, but when trying to get the user name (after the hyphen) I get this output:
{'host': '146.204.224.152', 'user_name': ' '}
This is the code I am using:
for item in re.finditer("(?P<host>[0-9]+(?:\.[0-9]+){3})(P<user_name>(?<=- )*\s)", logdata):
print(item.groupdict())
I'm a noob to regex. Any advice as to what I'm doing wrong?
The output I want should look like this:
{'host': '146.204.224.152', 'user_name': 'feest6811'}