problematic code:
out, err = shellcmd.run_get_out(shell_cmd, login_shell=True)
p = re.compile('^' + module + '/(.*)$')
m = p.match(out)
if m:
return m.group(1)
return None
It get the output from some shell command and do a regular expression match. For example: out is ‘rvct/4.1_0894\n’ and module is ‘rvct’, it returns ‘4.1_0894’
But on some system, the shell command output starts with a new line, the out will be ‘\nrvct/4.1_0894\n’, I have to make this change
p = re.compile('^\n' + module + '/(.*)$')
to make it work
Can I have a regex working on both situations? I have tried
p = re.compile('^' + module + '/(.*)$', re.MULTILINE)
It seems not working.
You can strip newlines from the output first, using
out.strip().