I am trying to create a list of dictionaries using regex positive lookbehind. I tried two different codes:
Variation 1
string = '146.204.224.152 - lubo233'
for item in re.finditer( "(?P<host>[0-9]*[.][0-9]*[.][0-9]*[.][0-9]*)(?P<user_name>(?<= - )[a-z]*[0-9]*)", string ):
print(item.groupdict())
Variation 2
string = '146.204.224.152 - lubo233'
for item in re.finditer( "(?P<host>[0-9]*[.][0-9]*[.][0-9]*[.][0-9]*)(?<= - )(?P<user_name>[a-z]*[0-9]*)", string ):
print(item.groupdict())
Desired Output
{'host': '146.204.224.152', 'user_name': 'lubo233'}
Question/Issue
In both cases, I am unable to eliminate the substring " - ".
The use of positive lookbehind (?<= - )
renders my code wrong.
Can anyone assist to identify my mistake? Thanks.