I have strings that includes names and sometime a username in a string followed by a datetime stamp:
GN1RLWFH0546-2020-04-10-18-09-52-563945.txt
JOHN-DOE-2020-04-10-18-09-52-563946t64.txt
DESKTOP-OHK45JO-2020-04-09-02-27-11-451975.txt
I want to extract the usernames from this string:
GN1RLWFH0546
JOHN-DOE
DESKTOP-OHK45JO
I have tried different regex patterns the closest I came to extract was following:
GN1RLWFH0546
DESKTOP
JOHN
Using the following regex pattern:
names = re.search(r"\(?([0-9A-Za-z]+)\)?", agent_str)
print(names.group(1))