I am trying to write a quick script to beautify a passwd file for a hack the box vm I am working on. I've run into trouble because the regex grabs more than I want it to.
I am using this as my regex pattern:
passwd_line_regex = re.compile(r'[a-zA-Z0-9_]+:[a-zA-Z0-9:*&_/\ ]+[/-][a-zA-Z0-9_]+\s{1}')
Then I am passing it this (smaller excerpt):
root:*:0:0:Charlie &:/root:/bin/csh toor:*:0:0:Bourne-again Superuser:.....
and using findall I get back a list, but instead of getting root::0:0:Charlie &:/root:/bin/csh AND toor::0:0:Bourne-again, I get them back together like this:
['root:*:0:0:Charlie &:/root:/bin/csh toor:*:0:0:Bourne-again ', 'Superuser:/....
How can I stop this behavior? I want it to stop at the first occurence of (/ or -)example(space), in this case, at the end of /bin/csh, but I am trying to find all entries, so I need to continue from that point with the next entry.