I would like to use the following regular expression in python and it was successfully tested with PCRE. Switching to python is giving me an error.
^password\s+sufficient\s+pam_unix\.so\s(?|.*?(remember=(?P<val>\d*))|()())?
My input file is
password sufficient pam_unix.so sha512 shadow use_authtok
password sufficient pam_unix.so sha512 shadow use_authtok remember=2
#password sufficient pam_unix.so sha512 shadow use_authtok remember=10
I'm expecting two matches with group_1 and group_2 each.
Match1 password sufficient pam_unix.so
Group1 empty string
Group2 empty string
Match2 password sufficient pam_unix.so sha512 shadow use_authtok remember=2
Group1 remember=2
Group2 2
It seems that python is not supporting branch resets, is there any alternative?